1
- /*
2
- Module: f32
3
-
4
- Floating point operations and constants for `f32`
5
- */
1
+ #[ doc = "Floating point operations and constants for `f32`" ] ;
6
2
7
3
// PORT
8
4
@@ -29,113 +25,87 @@ type t = f32;
29
25
// These are not defined inside consts:: for consistency with
30
26
// the integer types
31
27
32
- /* Const: NaN */
33
28
const NaN : f32 = 0.0_f32 /0.0_f32 ;
34
29
35
- /* Const: infinity */
36
30
const infinity: f32 = 1.0_f32 /0.0_f32 ;
37
31
38
- /* Const: neg_infinity */
39
32
const neg_infinity: f32 = -1.0_f32 /0.0_f32 ;
40
33
41
- /* Predicate: isNaN */
42
34
pure fn is_NaN ( f : f32 ) -> bool { f != f }
43
35
44
- /* Function: add */
45
36
pure fn add ( x : f32 , y : f32 ) -> f32 { ret x + y; }
46
37
47
- /* Function: sub */
48
38
pure fn sub ( x : f32 , y : f32 ) -> f32 { ret x - y; }
49
39
50
- /* Function: mul */
51
40
pure fn mul ( x : f32 , y : f32 ) -> f32 { ret x * y; }
52
41
53
- /* Function: div */
54
42
pure fn div ( x : f32 , y : f32 ) -> f32 { ret x / y; }
55
43
56
- /* Function: rem */
57
44
pure fn rem ( x : f32 , y : f32 ) -> f32 { ret x % y; }
58
45
59
- /* Predicate: lt */
60
46
pure fn lt ( x : f32 , y : f32 ) -> bool { ret x < y; }
61
47
62
- /* Predicate: le */
63
48
pure fn le ( x : f32 , y : f32 ) -> bool { ret x <= y; }
64
49
65
- /* Predicate: eq */
66
50
pure fn eq ( x : f32 , y : f32 ) -> bool { ret x == y; }
67
51
68
- /* Predicate: ne */
69
52
pure fn ne ( x : f32 , y : f32 ) -> bool { ret x != y; }
70
53
71
- /* Predicate: ge */
72
54
pure fn ge ( x : f32 , y : f32 ) -> bool { ret x >= y; }
73
55
74
- /* Predicate: gt */
75
56
pure fn gt ( x : f32 , y : f32 ) -> bool { ret x > y; }
76
57
77
58
// FIXME replace the predicates below with llvm intrinsics or calls
78
59
// to the libmath macros in the rust runtime for performance
79
60
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
+ ) ]
85
64
pure fn is_positive ( x : f32 ) -> bool
86
65
{ ret x > 0.0f32 || ( 1.0f32 /x) == infinity; }
87
66
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
+ ) ]
93
70
pure fn is_negative ( x : f32 ) -> bool
94
71
{ ret x < 0.0f32 || ( 1.0f32 /x) == neg_infinity; }
95
72
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
+ ) ]
102
78
pure fn is_nonpositive ( x : f32 ) -> bool {
103
79
ret x < 0.0f32 || ( 1.0f32 /x) == neg_infinity;
104
80
}
105
81
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
+ ) ]
112
87
pure fn is_nonnegative ( x : f32 ) -> bool {
113
88
ret x > 0.0f32 || ( 1.0f32 /x) == infinity;
114
89
}
115
90
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
+ ) ]
121
95
pure fn is_zero ( x : f32 ) -> bool {
122
96
ret x == 0.0f32 || x == -0.0f32 ;
123
97
}
124
98
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
+ ) ]
130
102
pure fn is_infinite ( x : f32 ) -> bool {
131
103
ret x == infinity || x == neg_infinity;
132
104
}
133
105
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
+ ) ]
139
109
pure fn is_finite ( x : f32 ) -> bool {
140
110
ret ! ( is_NaN( x) || is_infinite( x) ) ;
141
111
}
@@ -146,96 +116,69 @@ pure fn is_finite(x: f32) -> bool {
146
116
mod consts {
147
117
148
118
// FIXME replace with mathematical constants from cmath
149
-
150
- /*
151
- Const: pi
152
-
153
- Archimedes' constant
154
- */
119
+ #[ doc(
120
+ brief = "Archimedes' constant"
121
+ ) ]
155
122
const pi: f32 = 3.14159265358979323846264338327950288_f32 ;
156
123
157
- /*
158
- Const: frac_pi_2
159
-
160
- pi/2.0
161
- */
124
+ #[ doc(
125
+ brief = "pi/2.0"
126
+ ) ]
162
127
const frac_pi_2: f32 = 1.57079632679489661923132169163975144_f32 ;
163
128
164
- /*
165
- Const: frac_pi_4
166
-
167
- pi/4.0
168
- */
129
+ #[ doc(
130
+ brief = "pi/4.0"
131
+ ) ]
169
132
const frac_pi_4: f32 = 0.785398163397448309615660845819875721_f32 ;
170
133
171
- /*
172
- Const: frac_1_pi
173
-
174
- 1.0/pi
175
- */
134
+ #[ doc(
135
+ brief = "1.0/pi"
136
+ ) ]
176
137
const frac_1_pi: f32 = 0.318309886183790671537767526745028724_f32 ;
177
138
178
- /*
179
- Const: frac_2_pi
180
-
181
- 2.0/pi
182
- */
139
+ #[ doc(
140
+ brief = "2.0/pi"
141
+ ) ]
183
142
const frac_2_pi: f32 = 0.636619772367581343075535053490057448_f32 ;
184
143
185
- /*
186
- Const: frac_2_sqrtpi
187
-
188
- 2.0/sqrt(pi)
189
- */
144
+ #[ doc(
145
+ brief = "2.0/sqrt(pi)"
146
+ ) ]
190
147
const frac_2_sqrtpi: f32 = 1.12837916709551257389615890312154517_f32 ;
191
148
192
- /*
193
- Const: sqrt2
194
-
195
- sqrt(2.0)
196
- */
149
+ #[ doc(
150
+ brief = "sqrt(2.0)"
151
+ ) ]
197
152
const sqrt2: f32 = 1.41421356237309504880168872420969808_f32 ;
198
153
199
- /*
200
- Const: frac_1_sqrt2
201
-
202
- 1.0/sqrt(2.0)
203
- */
154
+ #[ doc(
155
+ brief = "1.0/sqrt(2.0)"
156
+ ) ]
204
157
const frac_1_sqrt2: f32 = 0.707106781186547524400844362104849039_f32 ;
205
158
206
- /*
207
- Const: e
208
-
209
- Euler's number
210
- */
159
+ #[ doc(
160
+ brief = "Euler's number"
161
+ ) ]
211
162
const e: f32 = 2.71828182845904523536028747135266250_f32 ;
212
163
213
- /*
214
- Const: log2_e
215
-
216
- log2(e)
217
- */
164
+ #[ doc(
165
+ brief = "log2(e)"
166
+ ) ]
218
167
const log2_e: f32 = 1.44269504088896340735992468100189214_f32 ;
219
168
220
- /*
221
- Const: log10_e
222
-
223
- log10(e)
224
- */
169
+ #[ doc(
170
+ brief = "log10(e)"
171
+ ) ]
225
172
const log10_e: f32 = 0.434294481903251827651128918916605082_f32 ;
226
173
227
- /*
228
- Const: ln_2
229
-
230
- ln(2.0)
231
- */
174
+ #[ doc(
175
+ brief = "ln(2.0)"
176
+ ) ]
232
177
const ln_2: f32 = 0.693147180559945309417232121458176568_f32 ;
233
178
234
- /*
235
- Const: ln_10
236
-
237
- ln(10.0)
238
- */
179
+ #[ doc(
180
+ brief = "ln(10.0)"
181
+ ) ]
239
182
const ln_10: f32 = 2.30258509299404568401799145468436421_f32 ;
240
183
}
241
184
0 commit comments