1- /*
2- Module: f32
3-
4- Floating point operations and constants for `f32`
5- */
1+ #[ doc = "Floating point operations and constants for `f32`" ] ;
62
73// PORT
84
@@ -29,113 +25,87 @@ type t = f32;
2925// These are not defined inside consts:: for consistency with
3026// the integer types
3127
32- /* Const: NaN */
3328const NaN : f32 = 0.0_f32 /0.0_f32 ;
3429
35- /* Const: infinity */
3630const infinity: f32 = 1.0_f32 /0.0_f32 ;
3731
38- /* Const: neg_infinity */
3932const neg_infinity: f32 = -1.0_f32 /0.0_f32 ;
4033
41- /* Predicate: isNaN */
4234pure fn is_NaN ( f : f32 ) -> bool { f != f }
4335
44- /* Function: add */
4536pure fn add ( x : f32 , y : f32 ) -> f32 { ret x + y; }
4637
47- /* Function: sub */
4838pure fn sub ( x : f32 , y : f32 ) -> f32 { ret x - y; }
4939
50- /* Function: mul */
5140pure fn mul ( x : f32 , y : f32 ) -> f32 { ret x * y; }
5241
53- /* Function: div */
5442pure fn div ( x : f32 , y : f32 ) -> f32 { ret x / y; }
5543
56- /* Function: rem */
5744pure fn rem ( x : f32 , y : f32 ) -> f32 { ret x % y; }
5845
59- /* Predicate: lt */
6046pure fn lt ( x : f32 , y : f32 ) -> bool { ret x < y; }
6147
62- /* Predicate: le */
6348pure fn le ( x : f32 , y : f32 ) -> bool { ret x <= y; }
6449
65- /* Predicate: eq */
6650pure fn eq ( x : f32 , y : f32 ) -> bool { ret x == y; }
6751
68- /* Predicate: ne */
6952pure fn ne ( x : f32 , y : f32 ) -> bool { ret x != y; }
7053
71- /* Predicate: ge */
7254pure fn ge ( x : f32 , y : f32 ) -> bool { ret x >= y; }
7355
74- /* Predicate: gt */
7556pure fn gt ( x : f32 , y : f32 ) -> bool { ret x > y; }
7657
7758// FIXME replace the predicates below with llvm intrinsics or calls
7859// to the libmath macros in the rust runtime for performance
7960
80- /*
81- Predicate: is_positive
82-
83- Returns true if `x` is a positive number, including +0.0f320 and +Infinity.
84- */
61+ #[ doc(
62+ brief = "Returns true if `x` is a positive number, including +0.0f320 and +Infinity."
63+ ) ]
8564pure fn is_positive ( x : f32 ) -> bool
8665 { ret x > 0.0f32 || ( 1.0f32 /x) == infinity; }
8766
88- /*
89- Predicate: is_negative
90-
91- Returns true if `x` is a negative number, including -0.0f320 and -Infinity.
92- */
67+ #[ doc(
68+ brief = "Returns true if `x` is a negative number, including -0.0f320 and -Infinity."
69+ ) ]
9370pure fn is_negative ( x : f32 ) -> bool
9471 { ret x < 0.0f32 || ( 1.0f32 /x) == neg_infinity; }
9572
96- /*
97- Predicate: is_nonpositive
98-
99- Returns true if `x` is a negative number, including -0.0f320 and -Infinity.
100- (This is the same as `f32::negative`.)
101- */
73+ #[ doc(
74+ brief = "Returns true if `x` is a negative number, including \
75+ -0.0f320 and -Infinity. (This is the same as \
76+ `f32::negative`.)"
77+ ) ]
10278pure fn is_nonpositive ( x : f32 ) -> bool {
10379 ret x < 0.0f32 || ( 1.0f32 /x) == neg_infinity;
10480}
10581
106- /*
107- Predicate: nonnegative
108-
109- Returns true if `x` is a positive number, including +0.0f320 and +Infinity.
110- (This is the same as `f32::positive`.)
111- */
82+ #[ doc(
83+ brief = "Returns true if `x` is a positive number, \
84+ including +0.0f320 and +Infinity. (This is \
85+ the same as `f32::positive`.)"
86+ ) ]
11287pure fn is_nonnegative ( x : f32 ) -> bool {
11388 ret x > 0.0f32 || ( 1.0f32 /x) == infinity;
11489}
11590
116- /*
117- Predicate: is_zero
118-
119- Returns true if `x` is a zero number (positive or negative zero)
120- */
91+ #[ doc(
92+ brief = "Returns true if `x` is a zero number \
93+ (positive or negative zero)"
94+ ) ]
12195pure fn is_zero ( x : f32 ) -> bool {
12296 ret x == 0.0f32 || x == -0.0f32 ;
12397}
12498
125- /*
126- Predicate: is_infinite
127-
128- Returns true if `x`is an infinite numer
129- */
99+ #[ doc(
100+ brief = "Returns true if `x`is an infinite number"
101+ ) ]
130102pure fn is_infinite ( x : f32 ) -> bool {
131103 ret x == infinity || x == neg_infinity;
132104}
133105
134- /*
135- Predicate: is_finite
136-
137- Returns true if `x`is a finite numer
138- */
106+ #[ doc(
107+ brief = "Returns true if `x`is a finite number"
108+ ) ]
139109pure fn is_finite ( x : f32 ) -> bool {
140110 ret ! ( is_NaN( x) || is_infinite( x) ) ;
141111}
@@ -146,96 +116,69 @@ pure fn is_finite(x: f32) -> bool {
146116mod consts {
147117
148118 // FIXME replace with mathematical constants from cmath
149-
150- /*
151- Const: pi
152-
153- Archimedes' constant
154- */
119+ #[ doc(
120+ brief = "Archimedes' constant"
121+ ) ]
155122 const pi: f32 = 3.14159265358979323846264338327950288_f32 ;
156123
157- /*
158- Const: frac_pi_2
159-
160- pi/2.0
161- */
124+ #[ doc(
125+ brief = "pi/2.0"
126+ ) ]
162127 const frac_pi_2: f32 = 1.57079632679489661923132169163975144_f32 ;
163128
164- /*
165- Const: frac_pi_4
166-
167- pi/4.0
168- */
129+ #[ doc(
130+ brief = "pi/4.0"
131+ ) ]
169132 const frac_pi_4: f32 = 0.785398163397448309615660845819875721_f32 ;
170133
171- /*
172- Const: frac_1_pi
173-
174- 1.0/pi
175- */
134+ #[ doc(
135+ brief = "1.0/pi"
136+ ) ]
176137 const frac_1_pi: f32 = 0.318309886183790671537767526745028724_f32 ;
177138
178- /*
179- Const: frac_2_pi
180-
181- 2.0/pi
182- */
139+ #[ doc(
140+ brief = "2.0/pi"
141+ ) ]
183142 const frac_2_pi: f32 = 0.636619772367581343075535053490057448_f32 ;
184143
185- /*
186- Const: frac_2_sqrtpi
187-
188- 2.0/sqrt(pi)
189- */
144+ #[ doc(
145+ brief = "2.0/sqrt(pi)"
146+ ) ]
190147 const frac_2_sqrtpi: f32 = 1.12837916709551257389615890312154517_f32 ;
191148
192- /*
193- Const: sqrt2
194-
195- sqrt(2.0)
196- */
149+ #[ doc(
150+ brief = "sqrt(2.0)"
151+ ) ]
197152 const sqrt2: f32 = 1.41421356237309504880168872420969808_f32 ;
198153
199- /*
200- Const: frac_1_sqrt2
201-
202- 1.0/sqrt(2.0)
203- */
154+ #[ doc(
155+ brief = "1.0/sqrt(2.0)"
156+ ) ]
204157 const frac_1_sqrt2: f32 = 0.707106781186547524400844362104849039_f32 ;
205158
206- /*
207- Const: e
208-
209- Euler's number
210- */
159+ #[ doc(
160+ brief = "Euler's number"
161+ ) ]
211162 const e: f32 = 2.71828182845904523536028747135266250_f32 ;
212163
213- /*
214- Const: log2_e
215-
216- log2(e)
217- */
164+ #[ doc(
165+ brief = "log2(e)"
166+ ) ]
218167 const log2_e: f32 = 1.44269504088896340735992468100189214_f32 ;
219168
220- /*
221- Const: log10_e
222-
223- log10(e)
224- */
169+ #[ doc(
170+ brief = "log10(e)"
171+ ) ]
225172 const log10_e: f32 = 0.434294481903251827651128918916605082_f32 ;
226173
227- /*
228- Const: ln_2
229-
230- ln(2.0)
231- */
174+ #[ doc(
175+ brief = "ln(2.0)"
176+ ) ]
232177 const ln_2: f32 = 0.693147180559945309417232121458176568_f32 ;
233178
234- /*
235- Const: ln_10
236-
237- ln(10.0)
238- */
179+ #[ doc(
180+ brief = "ln(10.0)"
181+ ) ]
239182 const ln_10: f32 = 2.30258509299404568401799145468436421_f32 ;
240183}
241184
0 commit comments