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

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