home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / MATH / EXP.S < prev    next >
Encoding:
Text File  |  1993-01-02  |  1.5 KB  |  48 lines

  1. / exp.s (emx+gcc) -- Copyright (c) 1991-1993 by Eberhard Mattes
  2.  
  3. #include <libm.h>
  4.  
  5.         .globl  _exp
  6.  
  7.         .text
  8.  
  9.         .align  2, 0x90
  10.  
  11. / double exp (double x)
  12.  
  13. #define cw1      0(%esp)
  14. #define cw2      2(%esp)
  15. /define ret_addr 4(%esp)
  16. #define x        8(%esp)
  17.  
  18. _exp:
  19.         subl    $4, %esp                / space for control words
  20.         fldl    x                       / x
  21.         fldl2e                          / log2 (e)
  22.         fmulp                           / y := x * log2 (e)
  23.         fstcww  cw1
  24.         movw    cw1, %ax
  25.         andw    $0xf3ff, %ax
  26.         orw     $0x0400, %ax            / round down towards -inf
  27.         movw    %ax, cw2
  28.         fldcww  cw2      
  29.         fldl    %st                     / y, y
  30.         frndint                         / int (y), y
  31.         fldcww  cw1
  32.         fxch    %st(1)                  / y, int (y)
  33.         fsub    %st(1), %st             / frac (y), int (y)
  34.         f2xm1                           / 2 ^ frac (y) - 1, int (y)
  35.         faddl   __const_ONE             / 2 ^ frac (y), int (y)
  36.         fscale                          / 2 ^ frac (y) * 2 ^ int (y), int (y)
  37.         fstp    %st(1)                  / 2 ^ frac (y) * 2 ^ int (y)
  38.         fstpl   x                       / convert to double
  39.         fldl    x
  40.         addl    $4, %esp                / Remove control words
  41.         _xam
  42.         j_inf   1f
  43.         ret
  44.  
  45.         .align  2, 0x90
  46. 1:      SETERRNO($ERANGE)
  47.         ret
  48.