half>bits ( float -- bits )


Vocabulary
math.floats.half

Inputs
floatan object


Outputs
bitsan object


Definition


: half>bits ( float -- bits )
float>bits [ -16 shift 32768 bitand ] keep
[ 8388607 bitand ] keep -23 shift 255 bitand 127 - {
{ [ dup -24 < ] [ 2drop 0 ] }
{ [ dup -14 < ] [ [ 1 + shift ] [ 24 + 2^ ] bi bitor ] }
{
[ dup 15 <= ]
[ [ -13 shift ] [ 15 + 10 shift ] bi* bitor ]
}
{ [ dup 128 < ] [ 2drop 31744 ] }
[ drop -13 shift 31744 bitor ]
} cond bitor ;