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

  1. / tanh.s (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes
  2.  
  3. #include <libm.h>
  4.  
  5.         .globl  _tanh
  6.  
  7.         .text
  8.  
  9.         .align  2, 0x90
  10.  
  11. / double tanh (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. / tanh(x) = (t-1.0) / (t+1.0) with t = exp (2.0 * x)
  19.  
  20. _tanh:
  21.         subl    $4, %esp                / space for control words
  22.         fldl    x                       / x
  23.         fmull   __const_TWO             / 2x
  24.         fldl2e                          / log2 (e)
  25.         fmulp                           / y := 2x * log2 (e)
  26.         fstcww  cw1
  27.         movw    cw1, %ax
  28.         andw    $0xf3ff, %ax
  29.         orw     $0x0400, %ax            / round down towards -inf
  30.         movw    %ax, cw2
  31.         fldcww  cw2      
  32.         fldl    %st                     / y, y
  33.         frndint                         / int (y), y
  34.         fldcww  cw1
  35.         fxch    %st(1)                  / y, int (y)
  36.         fsub    %st(1), %st             / frac (y), int (y)
  37.         f2xm1                           / 2 ^ frac (y) - 1, int (y)
  38.         faddl   __const_ONE             / 2 ^ frac (y), int (y)
  39.         fscale                          / 2 ^ frac (y) * 2 ^ int (y), int (y)
  40.         fstp    %st(1)                  / 2 ^ frac (y) * 2 ^ int (y)
  41.         fldl    %st                     / t, t
  42.         faddl   __const_ONE             / t+1, t
  43.         fxch    %st(1)                  / t, t+1
  44.         fsubl   __const_ONE             / t-1, t+1
  45.         fdivp                           / (t-1)/(t+1)
  46.         fstpl   x                       / convert to double
  47.         fldl    x
  48.         addl    $4, %esp                / Remove control words
  49.         _xam
  50.         j_inf   1f
  51.         ret
  52.  
  53.         .align  2, 0x90
  54. 1:      SETERRNO($ERANGE)
  55.         ret
  56.