2009-06-10 14:06:06 -04:00
|
|
|
! (c)2009 Joe Groff bsd license
|
2009-09-18 18:26:20 -04:00
|
|
|
USING: accessors alien.accessors alien.c-types alien.data
|
|
|
|
alien.syntax kernel math math.order ;
|
|
|
|
FROM: math => float ;
|
2010-04-28 18:48:47 -04:00
|
|
|
IN: math.floats.half
|
2009-06-10 14:06:06 -04:00
|
|
|
|
|
|
|
: half>bits ( float -- bits )
|
|
|
|
float>bits
|
|
|
|
[ -31 shift 15 shift ] [
|
2011-11-23 21:49:33 -05:00
|
|
|
0x7fffffff bitand
|
2009-06-10 14:06:06 -04:00
|
|
|
dup zero? [
|
2011-11-23 21:49:33 -05:00
|
|
|
dup 0x7f800000 >= [ -13 shift 0x7fff bitand ] [
|
2009-06-10 14:06:06 -04:00
|
|
|
-13 shift
|
|
|
|
112 10 shift -
|
2011-11-23 21:49:33 -05:00
|
|
|
0 0x7c00 clamp
|
2009-06-10 14:06:06 -04:00
|
|
|
] if
|
|
|
|
] unless
|
|
|
|
] bi bitor ;
|
|
|
|
|
|
|
|
: bits>half ( bits -- float )
|
|
|
|
[ -15 shift 31 shift ] [
|
2011-11-23 21:49:33 -05:00
|
|
|
0x7fff bitand
|
2009-06-10 14:06:06 -04:00
|
|
|
dup zero? [
|
2011-11-23 21:49:33 -05:00
|
|
|
dup 0x7c00 >= [ 13 shift 0x7f800000 bitor ] [
|
2009-06-10 14:06:06 -04:00
|
|
|
13 shift
|
2015-06-29 19:43:15 -04:00
|
|
|
112 23 shift +
|
2009-06-10 14:06:06 -04:00
|
|
|
] if
|
|
|
|
] unless
|
|
|
|
] bi bitor bits>float ;
|
|
|
|
|
2009-09-18 18:26:20 -04:00
|
|
|
SYMBOL: half
|
2009-06-10 14:06:06 -04:00
|
|
|
|
|
|
|
<<
|
|
|
|
|
2009-09-18 18:26:20 -04:00
|
|
|
<c-type>
|
|
|
|
float >>class
|
|
|
|
float >>boxed-class
|
|
|
|
[ alien-unsigned-2 bits>half ] >>getter
|
|
|
|
[ [ >float half>bits ] 2dip set-alien-unsigned-2 ] >>setter
|
|
|
|
2 >>size
|
|
|
|
2 >>align
|
2009-11-10 20:34:14 -05:00
|
|
|
2 >>align-first
|
2009-09-18 18:26:20 -04:00
|
|
|
[ >float ] >>unboxer-quot
|
2010-10-25 16:54:42 -04:00
|
|
|
\ half typedef
|
2009-06-10 14:06:06 -04:00
|
|
|
|
|
|
|
>>
|