?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.  ifndef included_xgeomean
  2.  define included_xgeomean
  3.  include "xmul.asm"
  4.  include "xsqrt.asm"
  5.  
  6.  if 1==1
  7. xgeomean:
  8. ;Input:
  9. ;  HL points to one number
  10. ;  DE points to anothers
  11. ;104+xmul+xsqrt
  12. ;avg: 16573.025
  13.   push hl
  14.   push bc
  15.   ld bc,xOP1
  16.   call xmul
  17.   ld h,b
  18.   ld l,c
  19.   pop bc
  20.   call xsqrt
  21.   pop hl
  22.   ret
  23.  
  24.  
  25.  
  26.  else
  27. xgeomean:
  28. ;Input:
  29. ;  HL points to x
  30. ;  DE points to y
  31. ;Returns sqrt(x*y)
  32. ;104+xmul+xsqrt   ;Needs to be corrected
  33. ;avg: 16573.025
  34.  
  35.   call pushpop
  36.   push bc
  37. ;Multiply x and y. This can cause an overflow or underflow, though, so we'll need to adjust the exponent! (The "correct" implmentation of geomean never underflows or overflows.)
  38.   push de
  39.   ld de,xOP1
  40.   call mov10
  41.   pop hl
  42.   call mov10
  43.         ld hl,(xOP1+8)
  44.         ld de,(xOP2+8)
  45.   res 7,h
  46.   res 7,d
  47.   add hl,de
  48.   ld a,h
  49.   rra
  50.   rr l
  51.   sub $40
  52.   ld h,a
  53.  
  54. ;Save the adjustment for later
  55.   ex (sp),hl
  56.   push hl
  57.  
  58. ; Now we set the new exponents
  59.   ld hl,$4000
  60.   ld d,h
  61.   ld e,l
  62.   ld (xOP2+8),hl
  63. ;If carry is set, 2nd exponent needs to be incremented
  64.   rl l
  65.   ld (xOP1+8),hl
  66.  
  67. ;Now actually multiply
  68.   call xmul_stepin_geomean
  69.  
  70. ;Now get the square root
  71.   ld hl,var_z+8
  72.   pop bc
  73.   call xsqrt
  74.  
  75. ; Now we need to adjust the exponent
  76.   ld hl,8
  77.   add hl,bc
  78.   pop bc
  79.   ld e,(hl)
  80.   inc hl
  81.   ld d,(hl)
  82.   ex de,hl
  83.   add hl,bc
  84.   ex de,hl
  85.   ld (hl),d
  86.   dec hl
  87.   ld (hl),e
  88.   ret
  89.  endif
  90.  endif
  91.