File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -214,12 +214,12 @@ fn NaN() -> float {
214
214
}
215
215
216
216
/* Function: infinity */
217
- fn infinity ( ) -> float {
217
+ pure fn infinity ( ) -> float {
218
218
ret 1. /0. ;
219
219
}
220
220
221
221
/* Function: neg_infinity */
222
- fn neg_infinity ( ) -> float {
222
+ pure fn neg_infinity ( ) -> float {
223
223
ret -1. /0. ;
224
224
}
225
225
@@ -257,16 +257,16 @@ pure fn ge(x: float, y: float) -> bool { ret x >= y; }
257
257
pure fn gt ( x : float , y : float ) -> bool { ret x > y; }
258
258
259
259
/* Predicate: positive */
260
- pure fn positive ( x : float ) -> bool { ret x > 0. ; }
260
+ pure fn positive ( x : float ) -> bool { ret x > 0. || ( 1. /x ) == infinity ( ) ; }
261
261
262
262
/* Predicate: negative */
263
- pure fn negative ( x : float ) -> bool { ret x < 0. ; }
263
+ pure fn negative ( x : float ) -> bool { ret x < 0. || ( 1. /x ) == neg_infinity ( ) ; }
264
264
265
265
/* Predicate: nonpositive */
266
- pure fn nonpositive ( x : float ) -> bool { ret x <= 0. ; }
266
+ pure fn nonpositive ( x : float ) -> bool { ret ! positive ( x ) ; }
267
267
268
268
/* Predicate: nonnegative */
269
- pure fn nonnegative ( x : float ) -> bool { ret x >= 0. ; }
269
+ pure fn nonnegative ( x : float ) -> bool { ret ! negative ( x ) ; }
270
270
271
271
//
272
272
// Local Variables:
Original file line number Diff line number Diff line change @@ -15,5 +15,24 @@ fn test_from_str() {
15
15
assert ( float:: from_str ( "5." ) == 5. ) ;
16
16
assert ( float:: from_str ( ".5" ) == 0.5 ) ;
17
17
assert ( float:: from_str ( "0.5" ) == 0.5 ) ;
18
+ }
18
19
20
+ #[ test]
21
+ fn test_positive ( ) {
22
+ assert ( float:: positive ( float:: infinity ( ) ) ) ;
23
+ assert ( float:: positive ( 1. ) ) ;
24
+ assert ( float:: positive ( 0. ) ) ;
25
+ assert ( !float:: positive ( -1. ) ) ;
26
+ assert ( !float:: positive ( float:: neg_infinity ( ) ) ) ;
27
+ assert ( !float:: positive ( 1. /float:: neg_infinity ( ) ) ) ;
28
+ }
29
+
30
+ #[ test]
31
+ fn test_negative ( ) {
32
+ assert ( !float:: negative ( float:: infinity ( ) ) ) ;
33
+ assert ( !float:: negative ( 1. ) ) ;
34
+ assert ( !float:: negative ( 0. ) ) ;
35
+ assert ( float:: negative ( -1. ) ) ;
36
+ assert ( float:: negative ( float:: neg_infinity ( ) ) ) ;
37
+ assert ( float:: negative ( 1. /float:: neg_infinity ( ) ) ) ;
19
38
}
You can’t perform that action at this time.
0 commit comments