?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.  ifndef included_xtanh
  2.  define included_xtanh
  3.  include "../common/pushpop.asm"
  4.  include "../common/mov.asm"
  5.  include "xrsub.asm"
  6.  include "xadd.asm"
  7.  include "xinv.asm"
  8.  include "xexp.asm"
  9.  include "constantsx.asm"
  10.  include "mul/xmul2.asm"
  11.  
  12. ;https://www.math.utah.edu/~beebe/software/ieee/tanh.pdf
  13. ;p0 = -1613.4119023996228053
  14. ;p1 = -99.225929672236083313
  15. ;p2 = -.96437492777225469787
  16. ;q0 = 4840.2357071988688686
  17. ;q1 = 2233.7720718962312926
  18. ;q2 = 112.74474380534949335
  19. ;g=x*x
  20. ;r = g * ((p2 * g + p1) * g + p0)/(((g + q2)*g + q1) * g + q0)
  21. ;return x+x*r
  22. ;
  23. ;tanh(a+b) = (tanh(a)+tanh(b))/(1+tanh(a)tanh(b))
  24. ;We could precompute a table for `a` from 1 to 23
  25.  
  26. xtanh:
  27. ;Just going to go with the standard method
  28. ;tanh(x) = sinh(x)/cosh(x)
  29. ;  = (e^x-e^-x)/(e^x+e^-x)
  30. ;  = 1-2/(e^2x+1)
  31.  
  32.   call pushpop
  33.   push bc
  34.   ld bc,xOP1
  35.   call xmul2
  36.   ld h,b
  37.   ld l,c
  38.   call xexp
  39.   ld de,xconst_1
  40.   call xadd
  41.   call xinv
  42.   call xmul2
  43.   pop bc
  44.   jp xrsub
  45.  endif
  46.