checkin so i can work with this elsewhere

db4
Doug Coleman 2008-10-21 21:51:54 -05:00
parent 9870a7d7cd
commit cfd1978aaa
3 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -0,0 +1,4 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test math.floating-point ;
IN: math.floating-point.tests

View File

@ -0,0 +1,32 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math sequences ;
IN: math.floating-point
: float-sign ( float -- ? )
float>bits -31 shift { 1 -1 } nth ;
: double-sign ( float -- ? )
double>bits -63 shift { 1 -1 } nth ;
: float-exponent-bits ( float -- n )
float>bits -23 shift 8 2^ 1- bitand ;
: double-exponent-bits ( double -- n )
double>bits -52 shift 11 2^ 1- bitand ;
: float-mantissa-bits ( float -- n )
float>bits 23 2^ 1- bitand ;
: double-mantissa-bits ( double -- n )
double>bits 52 2^ 1- bitand ;
: float-e ( -- float ) 127 ; inline
: double-e ( -- float ) 1023 ; inline
! : calculate-float ( S M E -- float )
! float-e - 2^ * * ; ! bits>float ;
! : calculate-double ( S M E -- frac )
! double-e - 2^ swap 52 2^ /f 1+ * * ;