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