?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  ifndef included_xln
  2.  define included_xln
  3.  include "../common/pushpop.asm"
  4.  include "../common/mov.asm"
  5.  include "constantsx.asm"
  6.  include "xmul.asm"
  7.  include "xamean.asm"
  8.  include "xsub.asm"
  9.  include "xbg.asm"
  10.  include "../conversion/i16tox.asm"
  11.  
  12.  
  13. ;NOTE! Doesn't yet check for special numbers!
  14. ;Not accurate on x<1, or some large x.
  15. ;
  16. ;We are going to compute ln(x) using the B-G algo.
  17. ;(x-1)/BG(.5(1+x), sqrt(x))
  18. var_x=xOP1+152 ;FIXME
  19. xln:
  20.   call pushpop
  21.   push bc
  22.   ld de,var_x
  23.   call mov10
  24.  
  25. ;ln(-x) == NaN
  26.   ld hl,(var_x+8)
  27.   ld a,h
  28.   add a,a
  29.   jr c,xln_return_NaN
  30.  
  31. ;ln(0), ln(NaN), ln(inf)
  32.   or l
  33.   jr z,xln_return_special
  34.  
  35. ;save the exponent
  36.   push hl
  37.  
  38. ;set exponent to 0
  39.   ld hl,$4000
  40.   ld (var_x+8),hl
  41.  
  42.   ld hl,var_x
  43.   ld bc,xOP5
  44.   call xsqrt
  45.   ld de,xconst_1
  46.   ld bc,xOP4
  47.   call xamean
  48.   ld b,h
  49.   ld c,l
  50.   call xsub
  51.   ld hl,xOP4
  52.   ld de,xOP5
  53.   ld b,h
  54.   ld c,l
  55.   call xbg
  56.   ld hl,var_x
  57.   ld d,b
  58.   ld e,c
  59.   ld b,h
  60.   ld c,l
  61.   call xmul
  62.  
  63.   pop hl
  64.   ld a,h
  65.   sub $40
  66.   ld h,a
  67.   ;need to do HL*ln(2)+var_x ==> BC
  68.   ld bc,xOP1
  69.   call i16tox
  70.   ld h,b
  71.   ld l,c
  72.   ld de,xconst_ln_2
  73.   call xmul
  74.   ld de,var_x
  75.   pop bc
  76.   jp xadd
  77. xln_return_special:
  78. ;ln(0) == -inf
  79. ;ln(inf) == inf; ln(NaN) == NaN
  80.   ld a,(var_x+7)
  81.   and $C0
  82.   jr nz,$+7
  83.   ld hl,xconst_nINF
  84.   jr xlnq;+_
  85.   jp m,xln_return_inf
  86. xln_return_NaN:
  87.   ld hl,xconst_NaN
  88.   jr xlnq;+_
  89. xln_return_inf:
  90.   ld hl,xconst_INF
  91. xlnq;_:
  92.   pop de
  93.   jp mov10
  94.  endif
  95.