float
Factor handbook » The language » Numbers » Floats

Next:>float ( x -- y )


Vocabulary
math

Class description
The class of double-precision floating point numbers.

Definition


Methods








































M: float >base
{
{ [ over fp-nan? ] [ drop fp-sign "-0/0." "0/0." ? ] }
{ [ over 1/0. = ] [ 2drop "1/0." ] }
{ [ over -1/0. = ] [ 2drop "-1/0." ] }
{ [ over 0.0 fp-bitwise= ] [ 2drop "0.0" ] }
{ [ over -0.0 fp-bitwise= ] [ 2drop "-0.0" ] }
[ float>base ]
} cond ;







































M: float e^-1
dup abs 0.7 < [
dup e^ dup 1.0 =
[ drop ] [ [ 1.0 - * ] [ log / ] bi ] if
] [ e^ 1.0 - ] if ; inline




































M: float item>xml
number>string 1 nenum T{ xml-chunk
{ seq
V{
""
T{ tag { name ~name~ } { children ~vector~ } }
""
}
}
} interpolate-xml ;






M: float ldexp
over fp-special? [ over zero? ] unless*
[ drop ] [
[ double>bits dup -52 shift 2047 bitand 1023 - ] dip + {
{ [ dup -1074 < ] [ drop 0 copysign ] }
{ [ dup 1023 > ] [ drop 0 < -1/0. 1/0. ? ] }
[
dup -1022 < [ 52 + -52 2^ ] [ 1 ] if
[ -9218868437227405313 bitand ]
[ 1023 + 52 shift bitor bits>double ] [ * ] tri*
]
} cond
] if ;




































M: float number>text
{
{ 1/0. [ "infinity" ] }
{ -1/0. [ "negative infinity" ] }
[
dup fp-nan?
[ drop "not a number" ] [
number>string "-" ?head swap "e-" split1 [
[ 46 swap remove ] dip string>number 1 -
48 <repetition> prepend "0" swap
] [
"e+" split1 [
~quotation~ dip string>number swap -
48 <repetition> append "0"
] [ "." split1 ] if*
] if* [ string>number number>text ] dip
[ 48 - small-numbers ] { } map-as
join-words " point " glue swap
[ "negative " prepend ] when
] if
]
} case ;