?login_element?

Subversion Repositories NedoOS

Rev

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

  1. #ifndef included_f24tof16
  2. #define included_f24tof16
  3.  
  4. f24tof16:
  5. ;convert an f24 float to an IEEE-754 binary16 format.
  6. ;Input: AHL is the input float
  7. ;Output: HL is the f16 float
  8. ;Destroys: AF, C
  9.  
  10.   ; check for special values
  11.   add a,a
  12.   jr z,f24tof16_return_0_noA
  13.   inc a
  14.   inc a
  15.   jr z,f24tof16_return_infnan
  16.   rr c    ; save the sign
  17. ; subtract 63 and add 15 to the sign, net -48
  18. ; Note that exponent is currently doubled plus two
  19.   sub 98
  20.   jr c,f24tof16_return_0
  21.   rra
  22.   cp 31
  23.   jr nc,f24tof16_return_inf
  24.   add hl,hl
  25.   rla
  26.   add hl,hl
  27.   rla
  28.   ; now get the sign
  29.   add a,a
  30.   rl c
  31.   rra
  32.   ; we'll round
  33.   sla l
  34.   ld l,h
  35.   ld h,a
  36.   ret nc
  37.   inc hl
  38.   ret
  39.  
  40. f24tof16_return_infnan:
  41.   ld a,%11111000
  42.   rra
  43.   ld c,a  ; sign and exponent set
  44.   ld a,h
  45.   or l
  46.   ld l,a  ; if the input was NaN, this will be non-zero, else zero
  47.   ld h,c
  48.   ret
  49.  
  50. f24tof16_return_inf:
  51.   rl c
  52.   ld a,%11111000
  53.   rra
  54.   ld h,a
  55.   ld l,0
  56.   ret
  57.  
  58. f24tof16_return_0:
  59.   xor a
  60.   rl c
  61. f24tof16_return_0_noA:
  62.   ld l,a
  63.   rra     ; shift the sign back in
  64.   ld h,a
  65.   ret
  66. #endif
  67.