Skip to content

Commit 57ac67a

Browse files
committed
core: killed all math wrappers
1 parent 49d36c7 commit 57ac67a

File tree

7 files changed

+194
-795
lines changed

7 files changed

+194
-795
lines changed

src/libcore/cmath.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
export c_double;
2+
export c_float;
3+
export bessel;
4+
15
import ctypes::c_int;
26
import ctypes::c_float;
37
import ctypes::c_double;
48

5-
// FIXME scalbn copysign
6-
79
#[link_name = "m"]
810
#[abi = "cdecl"]
911
native mod c_double {
@@ -16,6 +18,7 @@ native mod c_double {
1618
pure fn atan2(a: c_double, b: c_double) -> c_double;
1719
pure fn cbrt(n: c_double) -> c_double;
1820
pure fn ceil(n: c_double) -> c_double;
21+
pure fn copysign(x: c_double, y: c_double) -> c_double;
1922
pure fn cos(n: c_double) -> c_double;
2023
pure fn cosh(n: c_double) -> c_double;
2124
pure fn erf(n: c_double) -> c_double;
@@ -26,15 +29,16 @@ native mod c_double {
2629
#[link_name="fabs"] pure fn abs(n: c_double) -> c_double;
2730
#[link_name="fdim"] pure fn sub_pos(a: c_double, b: c_double) -> c_double;
2831
pure fn floor(n: c_double) -> c_double;
29-
#[link_name="fma"] pure fn mul_add(a: c_double, b: c_double, c: c_double) -> c_double;
32+
#[link_name="fma"] pure fn mul_add(a: c_double, b: c_double,
33+
c: c_double) -> c_double;
3034
#[link_name="fmax"] pure fn fmax(a: c_double, b: c_double) -> c_double;
3135
#[link_name="fmin"] pure fn fmin(a: c_double, b: c_double) -> c_double;
3236
pure fn nextafter(x: c_double, y: c_double) -> c_double;
33-
#[link_name="fmod"] pure fn rem(x: c_double, y: c_double) -> c_double;
3437
pure fn frexp(n: c_double, &value: c_int) -> c_double;
3538
pure fn hypot(x: c_double, y: c_double) -> c_double;
3639
pure fn ldexp(x: c_double, n: c_int) -> c_double;
37-
#[link_name="lgamma_r"] pure fn lgamma(n: c_double, &sign: c_int) -> c_double;
40+
#[link_name="lgamma_r"] pure fn lgamma(n: c_double,
41+
&sign: c_int) -> c_double;
3842
#[link_name="log"] pure fn ln(n: c_double) -> c_double;
3943
pure fn logb(n: c_double) -> c_double;
4044
#[link_name="log1p"] pure fn ln1p(n: c_double) -> c_double;
@@ -45,6 +49,7 @@ native mod c_double {
4549
pure fn pow(n: c_double, e: c_double) -> c_double;
4650
pure fn rint(n: c_double) -> c_double;
4751
pure fn round(n: c_double) -> c_double;
52+
pure fn scalbn(n: c_double, i: c_int) -> c_double;
4853
pure fn sin(n: c_double) -> c_double;
4954
pure fn sinh(n: c_double) -> c_double;
5055
pure fn sqrt(n: c_double) -> c_double;
@@ -66,6 +71,8 @@ native mod c_float {
6671
#[link_name="atan2f"] pure fn atan2(a: c_float, b: c_float) -> c_float;
6772
#[link_name="cbrtf"] pure fn cbrt(n: c_float) -> c_float;
6873
#[link_name="ceilf"] pure fn ceil(n: c_float) -> c_float;
74+
#[link_name="copysignf"] pure fn copysign(x: c_float,
75+
y: c_float) -> c_float;
6976
#[link_name="cosf"] pure fn cos(n: c_float) -> c_float;
7077
#[link_name="coshf"] pure fn cosh(n: c_float) -> c_float;
7178
#[link_name="erff"] pure fn erf(n: c_float) -> c_float;
@@ -76,25 +83,30 @@ native mod c_float {
7683
#[link_name="fabsf"] pure fn abs(n: c_float) -> c_float;
7784
#[link_name="fdimf"] pure fn sub_pos(a: c_float, b: c_float) -> c_float;
7885
#[link_name="floorf"] pure fn floor(n: c_float) -> c_float;
79-
#[link_name="frexpf"] pure fn frexp(n: c_double, &value: c_int) -> c_float;
80-
#[link_name="fmaf"] pure fn mul_add(a: c_float, b: c_float, c: c_float) -> c_float;
86+
#[link_name="frexpf"] pure fn frexp(n: c_double,
87+
&value: c_int) -> c_float;
88+
#[link_name="fmaf"] pure fn mul_add(a: c_float,
89+
b: c_float, c: c_float) -> c_float;
8190
#[link_name="fmaxf"] pure fn fmax(a: c_float, b: c_float) -> c_float;
8291
#[link_name="fminf"] pure fn fmin(a: c_float, b: c_float) -> c_float;
83-
#[link_name="nextafterf"] pure fn nextafter(x: c_float, y: c_float) -> c_float;
84-
#[link_name="fmodf"] pure fn rem(x: c_float, y: c_float) -> c_float;
92+
#[link_name="nextafterf"] pure fn nextafter(x: c_float,
93+
y: c_float) -> c_float;
8594
#[link_name="hypotf"] pure fn hypot(x: c_float, y: c_float) -> c_float;
8695
#[link_name="ldexpf"] pure fn ldexp(x: c_float, n: c_int) -> c_float;
87-
#[link_name="lgammaf_r"] pure fn lgamma(n: c_float, &sign: c_int) -> c_float;
96+
#[link_name="lgammaf_r"] pure fn lgamma(n: c_float,
97+
&sign: c_int) -> c_float;
8898
#[link_name="logf"] pure fn ln(n: c_float) -> c_float;
8999
#[link_name="logbf"] pure fn logb(n: c_float) -> c_float;
90100
#[link_name="log1p"] pure fn ln1p(n: c_double) -> c_double;
91101
#[link_name="log2f"] pure fn log2(n: c_float) -> c_float;
92102
#[link_name="log10f"] pure fn log10(n: c_float) -> c_float;
93103
#[link_name="ilogbf"] pure fn ilogb(n: c_float) -> c_int;
94-
#[link_name="modff"] pure fn modf(n: c_float, &iptr: c_float) -> c_float;
104+
#[link_name="modff"] pure fn modf(n: c_float,
105+
&iptr: c_float) -> c_float;
95106
#[link_name="powf"] pure fn pow(n: c_float, e: c_float) -> c_float;
96107
#[link_name="rintf"] pure fn rint(n: c_float) -> c_float;
97108
#[link_name="roundf"] pure fn round(n: c_float) -> c_float;
109+
#[link_name="scalbnf"] pure fn scalbn(n: c_float, i: c_int) -> c_float;
98110
#[link_name="sinf"] pure fn sin(n: c_float) -> c_float;
99111
#[link_name="sinhf"] pure fn sinh(n: c_float) -> c_float;
100112
#[link_name="sqrtf"] pure fn sqrt(n: c_float) -> c_float;

src/libcore/core.rc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
export box, char, float, f32, f64, int, str, ptr;
1111
export uint, u8, u32, u64, vec, bool;
1212
export either, option, result;
13-
export ctypes, mtypes, sys, unsafe, comm, task;
13+
export ctypes, sys, unsafe, comm, task;
1414
export extfmt;
1515

1616
// Built-in-type support modules

src/libcore/f32.rs

+81-104
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,94 @@
1-
21
/*
32
Module: f32
43
54
Floating point operations and constants for `f32`
6-
7-
This exposes the same operations as `math`, just for `f32` even though
8-
they do not show up in the docs right now!
95
*/
6+
// PORT
107

11-
export t;
12-
13-
export
14-
acos,
15-
asin,
16-
atan,
17-
atan2,
18-
cbrt,
19-
ceil,
20-
cos,
21-
cosh,
22-
erf,
23-
erfc,
24-
exp,
25-
expm1,
26-
exp2,
27-
abs,
28-
sub_pos,
29-
floor,
30-
mul_add,
31-
fmax,
32-
fmin,
33-
nextafter,
34-
frexp,
35-
hypot,
36-
ldexp,
37-
lgamma,
38-
ln,
39-
logb,
40-
ln1p,
41-
log10,
42-
log2,
43-
ilogb,
44-
modf,
45-
pow,
46-
rem,
47-
rint,
48-
round,
49-
sin,
50-
sinh,
51-
sqrt,
52-
tan,
53-
tanh,
54-
tgamma,
55-
trunc;
56-
57-
export consts;
58-
59-
export radix, mantissa_digits, digits, epsilon, min_value, max_value,
60-
min_exp, max_exp, min_10_exp, max_10_exp;
8+
import cmath::c_float::*;
619

62-
// PORT
10+
type t = f32;
6311

64-
import cops = cmath::c_float;
65-
66-
type t = f64;
67-
68-
import
69-
cops::acos,
70-
cops::asin,
71-
cops::atan,
72-
cops::atan2,
73-
cops::cbrt,
74-
cops::ceil,
75-
cops::cos,
76-
cops::cosh,
77-
cops::erf,
78-
cops::erfc,
79-
cops::exp,
80-
cops::expm1,
81-
cops::exp2,
82-
cops::abs,
83-
cops::sub_pos,
84-
cops::floor,
85-
cops::mul_add,
86-
cops::max,
87-
cops::min,
88-
cops::nextafter,
89-
cops::fmod,
90-
cops::frexp,
91-
cops::hypot,
92-
cops::ldexp,
93-
cops::lgamma,
94-
cops::ln,
95-
cops::logb,
96-
cops::ln1p,
97-
cops::log10,
98-
cops::log2,
99-
cops::ilogb,
100-
cops::modf,
101-
cops::pow,
102-
cops::rem,
103-
cops::rint,
104-
cops::round,
105-
cops::sin,
106-
cops::sinh,
107-
cops::sqrt,
108-
cops::tan,
109-
cops::tanh,
110-
cops::tgamma,
111-
cops::trunc;
12+
/* Const: NaN */
13+
const NaN: f32 = 0.0f32/0.0f32;
11214

15+
/* Const: infinity */
16+
const infinity: f32 = 1.0f32/0.0f32;
11317

114-
type t = f32;
18+
/* Const: neg_infinity */
19+
const neg_infinity: f32 = -1.0f32/0.0f32;
20+
21+
/* Predicate: isNaN */
22+
pure fn isNaN(f: f32) -> bool { f != f }
23+
24+
/* Function: add */
25+
pure fn add(x: f32, y: f32) -> f32 { ret x + y; }
26+
27+
/* Function: sub */
28+
pure fn sub(x: f32, y: f32) -> f32 { ret x - y; }
29+
30+
/* Function: mul */
31+
pure fn mul(x: f32, y: f32) -> f32 { ret x * y; }
32+
33+
/* Function: div */
34+
pure fn div(x: f32, y: f32) -> f32 { ret x / y; }
35+
36+
/* Function: rem */
37+
pure fn rem(x: f32, y: f32) -> f32 { ret x % y; }
38+
39+
/* Predicate: lt */
40+
pure fn lt(x: f32, y: f32) -> bool { ret x < y; }
41+
42+
/* Predicate: le */
43+
pure fn le(x: f32, y: f32) -> bool { ret x <= y; }
44+
45+
/* Predicate: eq */
46+
pure fn eq(x: f32, y: f32) -> bool { ret x == y; }
47+
48+
/* Predicate: ne */
49+
pure fn ne(x: f32, y: f32) -> bool { ret x != y; }
50+
51+
/* Predicate: ge */
52+
pure fn ge(x: f32, y: f32) -> bool { ret x >= y; }
53+
54+
/* Predicate: gt */
55+
pure fn gt(x: f32, y: f32) -> bool { ret x > y; }
56+
57+
/*
58+
Predicate: positive
59+
60+
Returns true if `x` is a positive number, including +0.0f320 and +Infinity.
61+
*/
62+
pure fn positive(x: f32) -> bool
63+
{ ret x > 0.0f32 || (1.0f32/x) == infinity; }
64+
65+
/*
66+
Predicate: negative
67+
68+
Returns true if `x` is a negative number, including -0.0f320 and -Infinity.
69+
*/
70+
pure fn negative(x: f32) -> bool
71+
{ ret x < 0.0f32 || (1.0f32/x) == neg_infinity; }
72+
73+
/*
74+
Predicate: nonpositive
75+
76+
Returns true if `x` is a negative number, including -0.0f320 and -Infinity.
77+
(This is the same as `f32::negative`.)
78+
*/
79+
pure fn nonpositive(x: f32) -> bool {
80+
ret x < 0.0f32 || (1.0f32/x) == neg_infinity;
81+
}
82+
83+
/*
84+
Predicate: nonnegative
85+
86+
Returns true if `x` is a positive number, including +0.0f320 and +Infinity.
87+
(This is the same as `f32::positive`.)
88+
*/
89+
pure fn nonnegative(x: f32) -> bool {
90+
ret x > 0.0f32 || (1.0f32/x) == infinity;
91+
}
11592

11693
/* Module: consts */
11794
mod consts {

0 commit comments

Comments
 (0)