6
6
7
7
// PORT
8
8
9
- use cmath:: c_float:: * ;
10
- use cmath:: c_float_targ_consts:: * ;
9
+ pub use cmath:: c_float:: * ;
10
+ pub use cmath:: c_float_targ_consts:: * ;
11
11
12
12
export add, sub, mul, div, rem, lt, le, eq, ne, ge, gt;
13
13
export is_positive, is_negative, is_nonpositive, is_nonnegative;
@@ -22,58 +22,56 @@ export lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix;
22
22
export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
23
23
export signbit;
24
24
25
- export num;
26
-
27
25
// These are not defined inside consts:: for consistency with
28
26
// the integer types
29
27
30
- const NaN : f32 = 0.0_f32 /0.0_f32 ;
28
+ pub const NaN : f32 = 0.0_f32 /0.0_f32 ;
31
29
32
- const infinity: f32 = 1.0_f32 /0.0_f32 ;
30
+ pub const infinity: f32 = 1.0_f32 /0.0_f32 ;
33
31
34
- const neg_infinity: f32 = -1.0_f32 /0.0_f32 ;
32
+ pub const neg_infinity: f32 = -1.0_f32 /0.0_f32 ;
35
33
36
- pure fn is_NaN ( f : f32 ) -> bool { f != f }
34
+ pub pure fn is_NaN ( f : f32 ) -> bool { f != f }
37
35
38
- pure fn add ( x : f32 , y : f32 ) -> f32 { return x + y; }
36
+ pub pure fn add ( x : f32 , y : f32 ) -> f32 { return x + y; }
39
37
40
- pure fn sub ( x : f32 , y : f32 ) -> f32 { return x - y; }
38
+ pub pure fn sub ( x : f32 , y : f32 ) -> f32 { return x - y; }
41
39
42
- pure fn mul ( x : f32 , y : f32 ) -> f32 { return x * y; }
40
+ pub pure fn mul ( x : f32 , y : f32 ) -> f32 { return x * y; }
43
41
44
- pure fn div ( x : f32 , y : f32 ) -> f32 { return x / y; }
42
+ pub pure fn div ( x : f32 , y : f32 ) -> f32 { return x / y; }
45
43
46
- pure fn rem ( x : f32 , y : f32 ) -> f32 { return x % y; }
44
+ pub pure fn rem ( x : f32 , y : f32 ) -> f32 { return x % y; }
47
45
48
- pure fn lt ( x : f32 , y : f32 ) -> bool { return x < y; }
46
+ pub pure fn lt ( x : f32 , y : f32 ) -> bool { return x < y; }
49
47
50
- pure fn le ( x : f32 , y : f32 ) -> bool { return x <= y; }
48
+ pub pure fn le ( x : f32 , y : f32 ) -> bool { return x <= y; }
51
49
52
- pure fn eq ( x : f32 , y : f32 ) -> bool { return x == y; }
50
+ pub pure fn eq ( x : f32 , y : f32 ) -> bool { return x == y; }
53
51
54
- pure fn ne ( x : f32 , y : f32 ) -> bool { return x != y; }
52
+ pub pure fn ne ( x : f32 , y : f32 ) -> bool { return x != y; }
55
53
56
- pure fn ge ( x : f32 , y : f32 ) -> bool { return x >= y; }
54
+ pub pure fn ge ( x : f32 , y : f32 ) -> bool { return x >= y; }
57
55
58
- pure fn gt ( x : f32 , y : f32 ) -> bool { return x > y; }
56
+ pub pure fn gt ( x : f32 , y : f32 ) -> bool { return x > y; }
59
57
60
58
// FIXME (#1999): replace the predicates below with llvm intrinsics or
61
59
// calls to the libmath macros in the rust runtime for performance.
62
60
63
61
/// Returns true if `x` is a positive number, including +0.0f320 and +Infinity
64
- pure fn is_positive ( x : f32 ) -> bool
62
+ pub pure fn is_positive ( x : f32 ) -> bool
65
63
{ return x > 0.0f32 || ( 1.0f32 /x) == infinity; }
66
64
67
65
/// Returns true if `x` is a negative number, including -0.0f320 and -Infinity
68
- pure fn is_negative ( x : f32 ) -> bool
66
+ pub pure fn is_negative ( x : f32 ) -> bool
69
67
{ return x < 0.0f32 || ( 1.0f32 /x) == neg_infinity; }
70
68
71
69
/**
72
70
* Returns true if `x` is a negative number, including -0.0f320 and -Infinity
73
71
*
74
72
* This is the same as `f32::is_negative`.
75
73
*/
76
- pure fn is_nonpositive ( x : f32 ) -> bool {
74
+ pub pure fn is_nonpositive ( x : f32 ) -> bool {
77
75
return x < 0.0f32 || ( 1.0f32 /x) == neg_infinity;
78
76
}
79
77
@@ -82,78 +80,76 @@ pure fn is_nonpositive(x: f32) -> bool {
82
80
*
83
81
* This is the same as `f32::is_positive`.)
84
82
*/
85
- pure fn is_nonnegative ( x : f32 ) -> bool {
83
+ pub pure fn is_nonnegative ( x : f32 ) -> bool {
86
84
return x > 0.0f32 || ( 1.0f32 /x) == infinity;
87
85
}
88
86
89
87
/// Returns true if `x` is a zero number (positive or negative zero)
90
- pure fn is_zero ( x : f32 ) -> bool {
88
+ pub pure fn is_zero ( x : f32 ) -> bool {
91
89
return x == 0.0f32 || x == -0.0f32 ;
92
90
}
93
91
94
92
/// Returns true if `x`is an infinite number
95
- pure fn is_infinite ( x : f32 ) -> bool {
93
+ pub pure fn is_infinite ( x : f32 ) -> bool {
96
94
return x == infinity || x == neg_infinity;
97
95
}
98
96
99
97
/// Returns true if `x`is a finite number
100
- pure fn is_finite ( x : f32 ) -> bool {
98
+ pub pure fn is_finite ( x : f32 ) -> bool {
101
99
return !( is_NaN ( x) || is_infinite ( x) ) ;
102
100
}
103
101
104
102
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify.
105
103
106
104
/* Module: consts */
107
- mod consts {
108
- #[ legacy_exports] ;
109
-
105
+ pub mod consts {
110
106
// FIXME (requires Issue #1433 to fix): replace with mathematical
111
107
// constants from cmath.
112
108
/// Archimedes' constant
113
- const pi: f32 = 3.14159265358979323846264338327950288_f32 ;
109
+ pub const pi: f32 = 3.14159265358979323846264338327950288_f32 ;
114
110
115
111
/// pi/2.0
116
- const frac_pi_2: f32 = 1.57079632679489661923132169163975144_f32 ;
112
+ pub const frac_pi_2: f32 = 1.57079632679489661923132169163975144_f32 ;
117
113
118
114
/// pi/4.0
119
- const frac_pi_4: f32 = 0.785398163397448309615660845819875721_f32 ;
115
+ pub const frac_pi_4: f32 = 0.785398163397448309615660845819875721_f32 ;
120
116
121
117
/// 1.0/pi
122
- const frac_1_pi: f32 = 0.318309886183790671537767526745028724_f32 ;
118
+ pub const frac_1_pi: f32 = 0.318309886183790671537767526745028724_f32 ;
123
119
124
120
/// 2.0/pi
125
- const frac_2_pi: f32 = 0.636619772367581343075535053490057448_f32 ;
121
+ pub const frac_2_pi: f32 = 0.636619772367581343075535053490057448_f32 ;
126
122
127
123
/// 2.0/sqrt(pi)
128
- const frac_2_sqrtpi: f32 = 1.12837916709551257389615890312154517_f32 ;
124
+ pub const frac_2_sqrtpi: f32 = 1.12837916709551257389615890312154517_f32 ;
129
125
130
126
/// sqrt(2.0)
131
- const sqrt2: f32 = 1.41421356237309504880168872420969808_f32 ;
127
+ pub const sqrt2: f32 = 1.41421356237309504880168872420969808_f32 ;
132
128
133
129
/// 1.0/sqrt(2.0)
134
- const frac_1_sqrt2: f32 = 0.707106781186547524400844362104849039_f32 ;
130
+ pub const frac_1_sqrt2: f32 = 0.707106781186547524400844362104849039_f32 ;
135
131
136
132
/// Euler's number
137
- const e: f32 = 2.71828182845904523536028747135266250_f32 ;
133
+ pub const e: f32 = 2.71828182845904523536028747135266250_f32 ;
138
134
139
135
/// log2(e)
140
- const log2_e: f32 = 1.44269504088896340735992468100189214_f32 ;
136
+ pub const log2_e: f32 = 1.44269504088896340735992468100189214_f32 ;
141
137
142
138
/// log10(e)
143
- const log10_e: f32 = 0.434294481903251827651128918916605082_f32 ;
139
+ pub const log10_e: f32 = 0.434294481903251827651128918916605082_f32 ;
144
140
145
141
/// ln(2.0)
146
- const ln_2: f32 = 0.693147180559945309417232121458176568_f32 ;
142
+ pub const ln_2: f32 = 0.693147180559945309417232121458176568_f32 ;
147
143
148
144
/// ln(10.0)
149
- const ln_10: f32 = 2.30258509299404568401799145468436421_f32 ;
145
+ pub const ln_10: f32 = 2.30258509299404568401799145468436421_f32 ;
150
146
}
151
147
152
- pure fn signbit ( x : f32 ) -> int {
148
+ pub pure fn signbit ( x : f32 ) -> int {
153
149
if is_negative ( x) { return 1 ; } else { return 0 ; }
154
150
}
155
151
156
- pure fn logarithm ( n : f32 , b : f32 ) -> f32 {
152
+ pub pure fn logarithm ( n : f32 , b : f32 ) -> f32 {
157
153
return log2 ( n) / log2 ( b) ;
158
154
}
159
155
0 commit comments