Skip to content

Commit 74cf6cc

Browse files
committed
---
yaml --- r: 7030 b: refs/heads/master c: 6284190 h: refs/heads/master v: v3
1 parent d2242ae commit 74cf6cc

File tree

12 files changed

+478
-685
lines changed

12 files changed

+478
-685
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 3971b520bcdd556ff78120c77ffd13785e1c3695
2+
refs/heads/master: 6284190ef9918e05cb9147a2a81100ddcb06fea8

trunk/src/libcore/bessel.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// PORT import module that is based on cmath::c_double here
2+
// (cant do better via libm; bessel functions only exist for c_double)
3+
4+
// code that wants to use bessel functions should use
5+
// values of type bessel::t and cast from/to float/f32/f64
6+
// when working with them at the peril of precision loss
7+
// for platform neutrality
8+
9+
import f64::*;
10+

trunk/src/libcore/cmath.rs

Lines changed: 123 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,146 @@
1+
export c_double;
2+
export c_float;
3+
14
import ctypes::c_int;
5+
import ctypes::c_float;
6+
import ctypes::c_double;
7+
8+
// function names are almost identical to C's libmath, a few have been
9+
// renamed, grep for "rename:"
210

311
#[link_name = "m"]
412
#[abi = "cdecl"]
5-
native mod f64 {
13+
native mod c_double {
614

715
// Alpabetically sorted by link_name
816

9-
pure fn acos(n: f64) -> f64;
10-
pure fn asin(n: f64) -> f64;
11-
pure fn atan(n: f64) -> f64;
12-
pure fn atan2(a: f64, b: f64) -> f64;
13-
pure fn ceil(n: f64) -> f64;
14-
pure fn cos(n: f64) -> f64;
15-
pure fn cosh(n: f64) -> f64;
16-
pure fn exp(n: f64) -> f64;
17-
#[link_name="fabs"] pure fn abs(n: f64) -> f64;
18-
pure fn floor(n: f64) -> f64;
19-
pure fn fmod(x: f64, y: f64) -> f64;
20-
pure fn frexp(n: f64, &value: c_int) -> f64;
21-
pure fn ldexp(x: f64, n: c_int) -> f64;
22-
#[link_name="log"] pure fn ln(n: f64) -> f64;
23-
#[link_name="log1p"] pure fn ln1p(n: f64) -> f64;
24-
pure fn log10(n: f64) -> f64;
17+
pure fn acos(n: c_double) -> c_double;
18+
pure fn asin(n: c_double) -> c_double;
19+
pure fn atan(n: c_double) -> c_double;
20+
pure fn atan2(a: c_double, b: c_double) -> c_double;
21+
pure fn cbrt(n: c_double) -> c_double;
22+
pure fn ceil(n: c_double) -> c_double;
23+
pure fn copysign(x: c_double, y: c_double) -> c_double;
24+
pure fn cos(n: c_double) -> c_double;
25+
pure fn cosh(n: c_double) -> c_double;
26+
pure fn erf(n: c_double) -> c_double;
27+
pure fn erfc(n: c_double) -> c_double;
28+
pure fn exp(n: c_double) -> c_double;
29+
pure fn expm1(n: c_double) -> c_double;
30+
pure fn exp2(n: c_double) -> c_double;
31+
#[link_name="fabs"] pure fn abs(n: c_double) -> c_double;
32+
// rename: for clarity and consistency with add/sub/mul/div
33+
#[link_name="fdim"] pure fn abs_sub(a: c_double, b: c_double) -> c_double;
34+
pure fn floor(n: c_double) -> c_double;
35+
// rename: for clarity and consistency with add/sub/mul/div
36+
#[link_name="fma"] pure fn mul_add(a: c_double, b: c_double,
37+
c: c_double) -> c_double;
38+
#[link_name="fmax"] pure fn fmax(a: c_double, b: c_double) -> c_double;
39+
#[link_name="fmin"] pure fn fmin(a: c_double, b: c_double) -> c_double;
40+
pure fn nextafter(x: c_double, y: c_double) -> c_double;
41+
pure fn frexp(n: c_double, &value: c_int) -> c_double;
42+
pure fn hypot(x: c_double, y: c_double) -> c_double;
43+
pure fn ldexp(x: c_double, n: c_int) -> c_double;
44+
#[link_name="lgamma_r"] pure fn lgamma(n: c_double,
45+
&sign: c_int) -> c_double;
46+
// renamed: log is a reserved keyword; ln seems more natural, too
47+
#[link_name="log"] pure fn ln(n: c_double) -> c_double;
48+
// renamed: "logb" /often/ is confused for log2 by beginners
49+
#[link_name="logb"] pure fn log_radix(n: c_double) -> c_double;
50+
// renamed: to be consitent with log as ln
51+
#[link_name="log1p"] pure fn ln1p(n: c_double) -> c_double;
52+
pure fn log10(n: c_double) -> c_double;
2553
#[cfg(target_os="linux")]
2654
#[cfg(target_os="macos")]
2755
#[cfg(target_os="win32")]
28-
pure fn log2(n: f64) -> f64;
29-
pure fn modf(n: f64, iptr: *f64) -> f64;
30-
pure fn pow(n: f64, e: f64) -> f64;
31-
pure fn rint(n: f64) -> f64;
32-
pure fn round(n: f64) -> f64;
33-
pure fn sin(n: f64) -> f64;
34-
pure fn sinh(n: f64) -> f64;
35-
pure fn sqrt(n: f64) -> f64;
36-
pure fn tan(n: f64) -> f64;
37-
pure fn tanh(n: f64) -> f64;
38-
pure fn trunc(n: f64) -> f64;
56+
pure fn log2(n: c_double) -> c_double;
57+
#[link_name="ilogb"] pure fn ilogradix(n: c_double) -> c_int;
58+
pure fn modf(n: c_double, &iptr: c_double) -> c_double;
59+
pure fn pow(n: c_double, e: c_double) -> c_double;
60+
// FIXME enable when rounding modes become available
61+
// pure fn rint(n: c_double) -> c_double;
62+
pure fn round(n: c_double) -> c_double;
63+
// rename: for consistency with logradix
64+
#[link_name="scalbn"] pure fn ldexp_radix(n: c_double, i: c_int) ->
65+
c_double;
66+
pure fn sin(n: c_double) -> c_double;
67+
pure fn sinh(n: c_double) -> c_double;
68+
pure fn sqrt(n: c_double) -> c_double;
69+
pure fn tan(n: c_double) -> c_double;
70+
pure fn tanh(n: c_double) -> c_double;
71+
pure fn tgamma(n: c_double) -> c_double;
72+
pure fn trunc(n: c_double) -> c_double;
73+
74+
// These are commonly only available for doubles
75+
76+
pure fn j0(n: c_double) -> c_double;
77+
pure fn j1(n: c_double) -> c_double;
78+
pure fn jn(i: c_int, n: c_double) -> c_double;
79+
80+
pure fn y0(n: c_double) -> c_double;
81+
pure fn y1(n: c_double) -> c_double;
82+
pure fn yn(i: c_int, n: c_double) -> c_double;
3983
}
4084

4185
#[link_name = "m"]
4286
#[abi = "cdecl"]
43-
native mod f32 {
87+
native mod c_float {
4488

4589
// Alpabetically sorted by link_name
4690

47-
#[link_name="acosf"] pure fn acos(n: f32) -> f32;
48-
#[link_name="asinf"] pure fn asin(n: f32) -> f32;
49-
#[link_name="atanf"] pure fn atan(n: f32) -> f32;
50-
#[link_name="atan2f"] pure fn atan2(a: f32, b: f32) -> f32;
51-
#[link_name="ceilf"] pure fn ceil(n: f32) -> f32;
52-
#[link_name="cosf"] pure fn cos(n: f32) -> f32;
53-
#[link_name="coshf"] pure fn cosh(n: f32) -> f32;
54-
#[link_name="expf"] pure fn exp(n: f32) -> f32;
55-
#[link_name="fabsf"] pure fn abs(n: f32) -> f32;
56-
#[link_name="floorf"] pure fn floor(n: f32) -> f32;
57-
#[link_name="frexpf"] pure fn frexp(n: f64, &value: c_int) -> f32;
58-
#[link_name="fmodf"] pure fn fmod(x: f32, y: f32) -> f32;
59-
#[link_name="ldexpf"] pure fn ldexp(x: f32, n: c_int) -> f32;
60-
#[link_name="logf"] pure fn ln(n: f32) -> f32;
61-
#[link_name="log1p"] pure fn ln1p(n: f64) -> f64;
91+
#[link_name="acosf"] pure fn acos(n: c_float) -> c_float;
92+
#[link_name="asinf"] pure fn asin(n: c_float) -> c_float;
93+
#[link_name="atanf"] pure fn atan(n: c_float) -> c_float;
94+
#[link_name="atan2f"] pure fn atan2(a: c_float, b: c_float) -> c_float;
95+
#[link_name="cbrtf"] pure fn cbrt(n: c_float) -> c_float;
96+
#[link_name="ceilf"] pure fn ceil(n: c_float) -> c_float;
97+
#[link_name="copysignf"] pure fn copysign(x: c_float,
98+
y: c_float) -> c_float;
99+
#[link_name="cosf"] pure fn cos(n: c_float) -> c_float;
100+
#[link_name="coshf"] pure fn cosh(n: c_float) -> c_float;
101+
#[link_name="erff"] pure fn erf(n: c_float) -> c_float;
102+
#[link_name="erfcf"] pure fn erfc(n: c_float) -> c_float;
103+
#[link_name="expf"] pure fn exp(n: c_float) -> c_float;
104+
#[link_name="expm1f"]pure fn expm1(n: c_float) -> c_float;
105+
#[link_name="exp2f"] pure fn exp2(n: c_float) -> c_float;
106+
#[link_name="fabsf"] pure fn abs(n: c_float) -> c_float;
107+
#[link_name="fdimf"] pure fn abs_sub(a: c_float, b: c_float) -> c_float;
108+
#[link_name="floorf"] pure fn floor(n: c_float) -> c_float;
109+
#[link_name="frexpf"] pure fn frexp(n: c_float,
110+
&value: c_int) -> c_float;
111+
#[link_name="fmaf"] pure fn mul_add(a: c_float,
112+
b: c_float, c: c_float) -> c_float;
113+
#[link_name="fmaxf"] pure fn fmax(a: c_float, b: c_float) -> c_float;
114+
#[link_name="fminf"] pure fn fmin(a: c_float, b: c_float) -> c_float;
115+
#[link_name="nextafterf"] pure fn nextafter(x: c_float,
116+
y: c_float) -> c_float;
117+
#[link_name="hypotf"] pure fn hypot(x: c_float, y: c_float) -> c_float;
118+
#[link_name="ldexpf"] pure fn ldexp(x: c_float, n: c_int) -> c_float;
119+
#[link_name="lgammaf_r"] pure fn lgamma(n: c_float,
120+
&sign: c_int) -> c_float;
121+
#[link_name="logf"] pure fn ln(n: c_float) -> c_float;
122+
#[link_name="logbf"] pure fn log_radix(n: c_float) -> c_float;
123+
#[link_name="log1pf"] pure fn ln1p(n: c_float) -> c_float;
62124
#[cfg(target_os="linux")]
63125
#[cfg(target_os="macos")]
64126
#[cfg(target_os="win32")]
65-
#[link_name="log2f"] pure fn log2(n: f32) -> f32;
66-
#[link_name="log10f"] pure fn log10(n: f32) -> f32;
67-
#[link_name="modff"] pure fn modf(n: f32, iptr: *f32) -> f32;
68-
#[link_name="powf"] pure fn pow(n: f32, e: f32) -> f32;
69-
#[link_name="rintf"] pure fn rint(n: f32) -> f32;
70-
#[link_name="roundf"] pure fn round(n: f32) -> f32;
71-
#[link_name="sinf"] pure fn sin(n: f32) -> f32;
72-
#[link_name="sinhf"] pure fn sinh(n: f32) -> f32;
73-
#[link_name="sqrtf"] pure fn sqrt(n: f32) -> f32;
74-
#[link_name="tanf"] pure fn tan(n: f32) -> f32;
75-
#[link_name="tanhf"] pure fn tanh(n: f32) -> f32;
76-
#[link_name="truncf"] pure fn trunc(n: f32) -> f32;
127+
#[link_name="log2f"] pure fn log2(n: c_float) -> c_float;
128+
#[link_name="log10f"] pure fn log10(n: c_float) -> c_float;
129+
#[link_name="ilogbf"] pure fn ilog_radix(n: c_float) -> c_int;
130+
#[link_name="modff"] pure fn modf(n: c_float,
131+
&iptr: c_float) -> c_float;
132+
#[link_name="powf"] pure fn pow(n: c_float, e: c_float) -> c_float;
133+
// FIXME enable when rounding modes become available
134+
// #[link_name="rintf"] pure fn rint(n: c_float) -> c_float;
135+
#[link_name="roundf"] pure fn round(n: c_float) -> c_float;
136+
#[link_name="scalbnf"] pure fn ldexp_radix(n: c_float, i: c_int) -> c_float;
137+
#[link_name="sinf"] pure fn sin(n: c_float) -> c_float;
138+
#[link_name="sinhf"] pure fn sinh(n: c_float) -> c_float;
139+
#[link_name="sqrtf"] pure fn sqrt(n: c_float) -> c_float;
140+
#[link_name="tanf"] pure fn tan(n: c_float) -> c_float;
141+
#[link_name="tanhf"] pure fn tanh(n: c_float) -> c_float;
142+
#[link_name="tgammaf"] pure fn tgamma(n: c_float) -> c_float;
143+
#[link_name="truncf"] pure fn trunc(n: c_float) -> c_float;
77144
}
78145

79146
//

trunk/src/libcore/core.rc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
#[license = "BSD"];
88
#[crate_type = "lib"];
99

10-
export box, char, float, f32, f64, int, str, ptr;
10+
export box, char, float, bessel, 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
1717

1818
mod box;
1919
mod char;
2020
mod float;
21+
mod bessel;
2122
mod f32;
2223
mod f64;
2324
mod int;
@@ -44,7 +45,6 @@ mod result;
4445
// Runtime and language-primitive support
4546

4647
mod ctypes;
47-
mod mtypes;
4848
mod cmath;
4949
mod sys;
5050
mod unsafe;

trunk/src/libcore/ctypes.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ FIXME: Add a test that uses some native code to verify these sizes,
99
which are not obviously correct for all potential platforms.
1010
*/
1111

12+
// PORT adapt to architecture
13+
1214
/*
1315
Type: c_int
1416

@@ -72,6 +74,20 @@ when interoperating with C void pointers can help in documentation.
7274
*/
7375
type void = int;
7476

77+
/*
78+
Type: c_float
79+
80+
A float value with the same size as a C `float`
81+
*/
82+
type c_float = f32;
83+
84+
/*
85+
Type: c_float
86+
87+
A float value with the same size as a C `double`
88+
*/
89+
type c_double = f64;
90+
7591
/*
7692
Type: size_t
7793

@@ -114,3 +130,4 @@ Type: enum
114130
An unsigned integer with the same size as a C enum
115131
*/
116132
type enum = u32;
133+

0 commit comments

Comments
 (0)