]> gitweb.factorcode.org Git - factor.git/blob - core/math/floats/floats-docs.factor
Fixing failing unit tests in compiler.tree.propagation due to constraints
[factor.git] / core / math / floats / floats-docs.factor
1 USING: help.markup help.syntax math math.private ;
2 IN: math.floats
3
4 HELP: float
5 { $class-description "The class of double-precision floating point numbers." } ;
6
7 HELP: >float
8 { $values { "x" real } { "y" float } }
9 { $description "Converts a real to a float. This is the identity on floats, and performs a floating point division on rationals." } ;
10
11 HELP: bits>double ( n -- x )
12 { $values { "n" "a 64-bit integer representing an IEEE 754 double-precision float" } { "x" float } }
13 { $description "Creates a " { $link float } " object from a 64-bit binary representation. This word is usually used to reconstruct floats read from streams." } ;
14
15 { bits>double bits>float double>bits float>bits } related-words
16
17 HELP: bits>float ( n -- x )
18 { $values { "n" "a 32-bit integer representing an IEEE 754 single-precision float" } { "x" float } }
19 { $description "Creates a " { $link float } " object from a 32-bit binary representation. This word is usually used to reconstruct floats read from streams." } ;
20
21 HELP: double>bits ( x -- n )
22 { $values { "x" float } { "n" "a 64-bit integer representing an IEEE 754 double-precision float" } }
23 { $description "Creates a 64-bit binary representation of a " { $link float } " object. This can be used in the process of writing a float to a stream." } ;
24
25 HELP: float>bits ( x -- n )
26 { $values { "x" float } { "n" "a 32-bit integer representing an IEEE 754 single-precision float" } }
27 { $description "Creates a 32-bit binary representation of a " { $link float } " object. This can be used in the process of writing a float to a stream." } ;
28
29 ! Unsafe primitives
30 HELP: float+ ( x y -- z )
31 { $values { "x" float } { "y" float } { "z" float } }
32 { $description "Primitive version of " { $link + } "." }
33 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link + } " instead." } ;
34
35 HELP: float- ( x y -- z )
36 { $values { "x" float } { "y" float } { "z" float } }
37 { $description "Primitive version of " { $link - } "." }
38 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link - } " instead." } ;
39
40 HELP: float* ( x y -- z )
41 { $values { "x" float } { "y" float } { "z" float } }
42 { $description "Primitive version of " { $link * } "." }
43 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link * } " instead." } ;
44
45 HELP: float-mod ( x y -- z )
46 { $values { "x" float } { "y" float } { "z" float } }
47 { $description "Primitive version of " { $link mod } "." }
48 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link mod } " instead." } ;
49
50 HELP: float/f ( x y -- z )
51 { $values { "x" float } { "y" float } { "z" float } }
52 { $description "Primitive version of " { $link /f } "." }
53 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link /f } " instead." } ;
54
55 HELP: float< ( x y -- ? )
56 { $values { "x" float } { "y" float } { "?" "a boolean" } }
57 { $description "Primitive version of " { $link < } "." }
58 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link < } " instead." } ;
59
60 HELP: float<= ( x y -- ? )
61 { $values { "x" float } { "y" float } { "?" "a boolean" } }
62 { $description "Primitive version of " { $link <= } "." }
63 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link <= } " instead." } ;
64
65 HELP: float> ( x y -- ? )
66 { $values { "x" float } { "y" float } { "?" "a boolean" } }
67 { $description "Primitive version of " { $link > } "." }
68 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link > } " instead." } ;
69
70 HELP: float>= ( x y -- ? )
71 { $values { "x" float } { "y" float } { "?" "a boolean" } }
72 { $description "Primitive version of " { $link >= } "." }
73 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link >= } " instead." } ;
74
75 ARTICLE: "floats" "Floats"
76 { $subsection float }
77 "Rational numbers represent " { $emphasis "exact" } " quantities. On the other hand, a floating point number is an " { $emphasis "approximate" } " value. While rationals can grow to any required precision, floating point numbers have limited precision, and manipulating them is usually faster than manipulating ratios or bignums."
78 $nl
79 "Introducing a floating point number in a computation forces the result to be expressed in floating point."
80 { $example "5/4 1/2 + ." "1+3/4" }
81 { $example "5/4 0.5 + ." "1.75" }
82 "Integers and rationals can be converted to floats:"
83 { $subsection >float }
84 "Two real numbers can be divided yielding a float result:"
85 { $subsection /f }
86 "Floating point numbers are represented internally in IEEE 754 double-precision format. This internal representation can be accessed for advanced operations and input/output purposes."
87 { $subsection float>bits }
88 { $subsection double>bits }
89 { $subsection bits>float }
90 { $subsection bits>double }
91 "Constructing floating point NaNs:"
92 { $subsection <fp-nan> }
93 "Floating point numbers are discrete:"
94 { $subsection prev-float }
95 { $subsection next-float }
96 "Introspection on floating point numbers:"
97 { $subsection fp-special? }
98 { $subsection fp-nan? }
99 { $subsection fp-qnan? }
100 { $subsection fp-snan? }
101 { $subsection fp-infinity? }
102 { $subsection fp-nan-payload }
103 "Comparing two floating point numbers:"
104 { $subsection fp-bitwise= }
105 { $see-also "syntax-floats" } ;
106
107 ABOUT: "floats"