@@ -105,38 +105,52 @@ pub const infinity: f32 = 1.0_f32/0.0_f32;
105
105
106
106
pub const neg_infinity: f32 = -1.0_f32 /0.0_f32 ;
107
107
108
+ #[ inline( always) ]
108
109
pub pure fn is_NaN ( f : f32 ) -> bool { f != f }
109
110
111
+ #[ inline( always) ]
110
112
pub pure fn add ( x : f32 , y : f32 ) -> f32 { return x + y; }
111
113
114
+ #[ inline( always) ]
112
115
pub pure fn sub ( x : f32 , y : f32 ) -> f32 { return x - y; }
113
116
117
+ #[ inline( always) ]
114
118
pub pure fn mul ( x : f32 , y : f32 ) -> f32 { return x * y; }
115
119
120
+ #[ inline( always) ]
116
121
pub pure fn div ( x : f32 , y : f32 ) -> f32 { return x / y; }
117
122
123
+ #[ inline( always) ]
118
124
pub pure fn rem ( x : f32 , y : f32 ) -> f32 { return x % y; }
119
125
126
+ #[ inline( always) ]
120
127
pub pure fn lt ( x : f32 , y : f32 ) -> bool { return x < y; }
121
128
129
+ #[ inline( always) ]
122
130
pub pure fn le ( x : f32 , y : f32 ) -> bool { return x <= y; }
123
131
132
+ #[ inline( always) ]
124
133
pub pure fn eq ( x : f32 , y : f32 ) -> bool { return x == y; }
125
134
135
+ #[ inline( always) ]
126
136
pub pure fn ne ( x : f32 , y : f32 ) -> bool { return x != y; }
127
137
138
+ #[ inline( always) ]
128
139
pub pure fn ge ( x : f32 , y : f32 ) -> bool { return x >= y; }
129
140
141
+ #[ inline( always) ]
130
142
pub pure fn gt ( x : f32 , y : f32 ) -> bool { return x > y; }
131
143
132
144
// FIXME (#1999): replace the predicates below with llvm intrinsics or
133
145
// calls to the libmath macros in the rust runtime for performance.
134
146
135
147
/// Returns true if `x` is a positive number, including +0.0f320 and +Infinity
148
+ #[ inline( always) ]
136
149
pub pure fn is_positive ( x : f32 ) -> bool
137
150
{ return x > 0.0f32 || ( 1.0f32 /x) == infinity; }
138
151
139
152
/// Returns true if `x` is a negative number, including -0.0f320 and -Infinity
153
+ #[ inline( always) ]
140
154
pub pure fn is_negative ( x : f32 ) -> bool
141
155
{ return x < 0.0f32 || ( 1.0f32 /x) == neg_infinity; }
142
156
@@ -145,6 +159,7 @@ pub pure fn is_negative(x: f32) -> bool
145
159
*
146
160
* This is the same as `f32::is_negative`.
147
161
*/
162
+ #[ inline( always) ]
148
163
pub pure fn is_nonpositive ( x : f32 ) -> bool {
149
164
return x < 0.0f32 || ( 1.0f32 /x) == neg_infinity;
150
165
}
@@ -154,21 +169,25 @@ pub pure fn is_nonpositive(x: f32) -> bool {
154
169
*
155
170
* This is the same as `f32::is_positive`.)
156
171
*/
172
+ #[ inline( always) ]
157
173
pub pure fn is_nonnegative ( x : f32 ) -> bool {
158
174
return x > 0.0f32 || ( 1.0f32 /x) == infinity;
159
175
}
160
176
161
177
/// Returns true if `x` is a zero number (positive or negative zero)
178
+ #[ inline( always) ]
162
179
pub pure fn is_zero ( x : f32 ) -> bool {
163
180
return x == 0.0f32 || x == -0.0f32 ;
164
181
}
165
182
166
183
/// Returns true if `x`is an infinite number
184
+ #[ inline( always) ]
167
185
pub pure fn is_infinite ( x : f32 ) -> bool {
168
186
return x == infinity || x == neg_infinity;
169
187
}
170
188
171
189
/// Returns true if `x`is a finite number
190
+ #[ inline( always) ]
172
191
pub pure fn is_finite ( x : f32 ) -> bool {
173
192
return !( is_NaN ( x) || is_infinite ( x) ) ;
174
193
}
@@ -219,45 +238,63 @@ pub mod consts {
219
238
pub const ln_10: f32 = 2.30258509299404568401799145468436421_f32 ;
220
239
}
221
240
241
+ #[ inline( always) ]
222
242
pub pure fn signbit ( x : f32 ) -> int {
223
243
if is_negative ( x) { return 1 ; } else { return 0 ; }
224
244
}
225
245
246
+ #[ inline( always) ]
226
247
pub pure fn logarithm ( n : f32 , b : f32 ) -> f32 {
227
248
return log2 ( n) / log2 ( b) ;
228
249
}
229
250
230
251
#[ cfg( notest) ]
231
252
impl f32 : cmp:: Eq {
253
+ #[ inline( always) ]
232
254
pure fn eq ( & self , other : & f32 ) -> bool { ( * self ) == ( * other) }
255
+ #[ inline( always) ]
233
256
pure fn ne ( & self , other : & f32 ) -> bool { ( * self ) != ( * other) }
234
257
}
235
258
236
259
#[ cfg( notest) ]
237
260
impl f32 : cmp:: Ord {
261
+ #[ inline( always) ]
238
262
pure fn lt ( & self , other : & f32 ) -> bool { ( * self ) < ( * other) }
263
+ #[ inline( always) ]
239
264
pure fn le ( & self , other : & f32 ) -> bool { ( * self ) <= ( * other) }
265
+ #[ inline( always) ]
240
266
pure fn ge ( & self , other : & f32 ) -> bool { ( * self ) >= ( * other) }
267
+ #[ inline( always) ]
241
268
pure fn gt ( & self , other : & f32 ) -> bool { ( * self ) > ( * other) }
242
269
}
243
270
244
271
impl f32 : num:: Num {
272
+ #[ inline( always) ]
245
273
pure fn add ( & self , other : & f32 ) -> f32 { return * self + * other; }
274
+ #[ inline( always) ]
246
275
pure fn sub ( & self , other : & f32 ) -> f32 { return * self - * other; }
276
+ #[ inline( always) ]
247
277
pure fn mul ( & self , other : & f32 ) -> f32 { return * self * * other; }
278
+ #[ inline( always) ]
248
279
pure fn div ( & self , other : & f32 ) -> f32 { return * self / * other; }
280
+ #[ inline( always) ]
249
281
pure fn modulo ( & self , other : & f32 ) -> f32 { return * self % * other; }
282
+ #[ inline( always) ]
250
283
pure fn neg ( & self ) -> f32 { return -* self ; }
251
284
285
+ #[ inline( always) ]
252
286
pure fn to_int ( & self ) -> int { return * self as int ; }
287
+ #[ inline( always) ]
253
288
static pure fn from_int( n: int ) -> f32 { return n as f32 ; }
254
289
}
255
290
256
291
impl f32 : num:: Zero {
292
+ #[ inline( always) ]
257
293
static pure fn zero( ) -> f32 { 0.0 }
258
294
}
259
295
260
296
impl f32 : num:: One {
297
+ #[ inline( always) ]
261
298
static pure fn one( ) -> f32 { 1.0 }
262
299
}
263
300
0 commit comments