Skip to content

Commit ad32804

Browse files
bogglegraydon
authored andcommitted
---
yaml --- r: 6707 b: refs/heads/master c: 50db7ce h: refs/heads/master i: 6705: 1373e9c 6703: 77adc3f v: v3
1 parent 1d26981 commit ad32804

File tree

9 files changed

+790
-34
lines changed

9 files changed

+790
-34
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: 6d0901cb4da43d9316762445f764904a6b4fe1cf
2+
refs/heads/master: 50db7ce906b9731a5dc02a1a87fbe87f55f13b42

trunk/src/libcore/cmath.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import ctypes::c_int;
2+
3+
#[link_name = "m"]
4+
#[abi = "cdecl"]
5+
native mod f64 {
6+
7+
// Alpabetically sorted by link_name
8+
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;
25+
pure fn log2(n: f64) -> f64;
26+
pure fn modf(n: f64, iptr: *f64) -> f64;
27+
pure fn pow(n: f64, e: f64) -> f64;
28+
pure fn rint(n: f64) -> f64;
29+
pure fn round(n: f64) -> f64;
30+
pure fn sin(n: f64) -> f64;
31+
pure fn sinh(n: f64) -> f64;
32+
pure fn sqrt(n: f64) -> f64;
33+
pure fn tan(n: f64) -> f64;
34+
pure fn tanh(n: f64) -> f64;
35+
pure fn trunc(n: f64) -> f64;
36+
}
37+
38+
#[link_name = "m"]
39+
#[abi = "cdecl"]
40+
native mod f32 {
41+
42+
// Alpabetically sorted by link_name
43+
44+
#[link_name="acosf"] pure fn acos(n: f32) -> f32;
45+
#[link_name="asinf"] pure fn asin(n: f32) -> f32;
46+
#[link_name="atanf"] pure fn atan(n: f32) -> f32;
47+
#[link_name="atan2f"] pure fn atan2(a: f32, b: f32) -> f32;
48+
#[link_name="ceilf"] pure fn ceil(n: f32) -> f32;
49+
#[link_name="cosf"] pure fn cos(n: f32) -> f32;
50+
#[link_name="coshf"] pure fn cosh(n: f32) -> f32;
51+
#[link_name="expf"] pure fn exp(n: f32) -> f32;
52+
#[link_name="fabsf"] pure fn abs(n: f32) -> f32;
53+
#[link_name="floorf"] pure fn floor(n: f32) -> f32;
54+
#[link_name="frexpf"] pure fn frexp(n: f64, &value: c_int) -> f32;
55+
#[link_name="fmodf"] pure fn fmod(x: f32, y: f32) -> f32;
56+
#[link_name="ldexpf"] pure fn ldexp(x: f32, n: c_int) -> f32;
57+
#[link_name="logf"] pure fn ln(n: f32) -> f32;
58+
#[link_name="log1p"] pure fn ln1p(n: f64) -> f64;
59+
#[link_name="log2f"] pure fn log2(n: f32) -> f32;
60+
#[link_name="log10f"] pure fn log10(n: f32) -> f32;
61+
#[link_name="modff"] pure fn modf(n: f32, iptr: *f32) -> f32;
62+
#[link_name="powf"] pure fn pow(n: f32, e: f32) -> f32;
63+
#[link_name="rintf"] pure fn rint(n: f32) -> f32;
64+
#[link_name="roundf"] pure fn round(n: f32) -> f32;
65+
#[link_name="sinf"] pure fn sin(n: f32) -> f32;
66+
#[link_name="sinhf"] pure fn sinh(n: f32) -> f32;
67+
#[link_name="sqrtf"] pure fn sqrt(n: f32) -> f32;
68+
#[link_name="tanf"] pure fn tan(n: f32) -> f32;
69+
#[link_name="tanhf"] pure fn tanh(n: f32) -> f32;
70+
#[link_name="truncf"] pure fn trunc(n: f32) -> f32;
71+
}
72+
73+
//
74+
// Local Variables:
75+
// mode: rust
76+
// fill-column: 78;
77+
// indent-tabs-mode: nil
78+
// c-basic-offset: 4
79+
// buffer-file-coding-system: utf-8-unix
80+
// End:
81+
//
82+

trunk/src/libcore/core.rc

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

10-
export box, char, float, int, str, ptr, uint, u8, u32, u64, vec, bool;
10+
export box, char, float, f32, f64, int, str, ptr;
11+
export uint, u8, u32, u64, vec, bool;
1112
export either, option, result;
12-
export ctypes, sys, unsafe, comm, task;
13+
export ctypes, mtypes, sys, unsafe, comm, task;
1314
export extfmt;
1415

1516
// Built-in-type support modules
1617

1718
mod box;
1819
mod char;
1920
mod float;
21+
mod f32;
22+
mod f64;
2023
mod int;
2124
mod str;
2225
mod ptr;
@@ -38,6 +41,8 @@ mod result;
3841
// Runtime and language-primitive support
3942

4043
mod ctypes;
44+
mod mtypes;
45+
mod cmath;
4146
mod sys;
4247
mod unsafe;
4348
mod comm;

trunk/src/libcore/ctypes.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,36 +72,6 @@ when interoperating with C void pointers can help in documentation.
7272
*/
7373
type void = int;
7474

75-
// machine type equivalents of rust int, uint, float
76-
77-
/*
78-
Type: m_int
79-
80-
FIXME: What C type does this represent?
81-
*/
82-
#[cfg(target_arch="x86")]
83-
type m_int = i32;
84-
#[cfg(target_arch="x86_64")]
85-
type m_int = i64;
86-
87-
/*
88-
Type: m_uint
89-
90-
FIXME: What C type does this represent?
91-
*/
92-
#[cfg(target_arch="x86")]
93-
type m_uint = u32;
94-
#[cfg(target_arch="x86_64")]
95-
type m_uint = u64;
96-
97-
// This *must* match with "import m_float = fXX" in std::math per arch
98-
/*
99-
Type: m_float
100-
101-
FIXME: What C type does this represent?
102-
*/
103-
type m_float = f64;
104-
10575
/*
10676
Type: size_t
10777

trunk/src/libcore/f32.rs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
2+
/*
3+
Module: f32
4+
5+
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!
9+
*/
10+
11+
import cmath::f32::*;
12+
13+
export
14+
acos, asin, atan, atan2, ceil, cos, cosh, exp, abs, floor, fmod,
15+
frexp, ldexp, ln, ln1p, log10, log2, modf, rint, round, pow, sin,
16+
sinh, sqrt, tan, tanh, trunc, t;
17+
18+
export consts;
19+
20+
type t = f32;
21+
22+
/* Module: consts */
23+
mod consts {
24+
25+
/*
26+
Const: pi
27+
28+
Archimedes' constant
29+
*/
30+
const pi: f32 = 3.14159265358979323846264338327950288f32;
31+
32+
/*
33+
Const: frac_pi_2
34+
35+
pi/2.0
36+
*/
37+
const frac_pi_2: f32 = 1.57079632679489661923132169163975144f32;
38+
39+
/*
40+
Const: frac_pi_4
41+
42+
pi/4.0
43+
*/
44+
const frac_pi_4: f32 = 0.785398163397448309615660845819875721f32;
45+
46+
/*
47+
Const: frac_1_pi
48+
49+
1.0/pi
50+
*/
51+
const frac_1_pi: f32 = 0.318309886183790671537767526745028724f32;
52+
53+
/*
54+
Const: frac_2_pi
55+
56+
2.0/pi
57+
*/
58+
const frac_2_pi: f32 = 0.636619772367581343075535053490057448f32;
59+
60+
/*
61+
Const: frac_2_sqrtpi
62+
63+
2.0/sqrt(pi)
64+
*/
65+
const frac_2_sqrtpi: f32 = 1.12837916709551257389615890312154517f32;
66+
67+
/*
68+
Const: sqrt2
69+
70+
sqrt(2.0)
71+
*/
72+
const sqrt2: f32 = 1.41421356237309504880168872420969808f32;
73+
74+
/*
75+
Const: frac_1_sqrt2
76+
77+
1.0/sqrt(2.0)
78+
*/
79+
const frac_1_sqrt2: f32 = 0.707106781186547524400844362104849039f32;
80+
81+
/*
82+
Const: e
83+
84+
Euler's number
85+
*/
86+
const e: f32 = 2.71828182845904523536028747135266250f32;
87+
88+
/*
89+
Const: log2_e
90+
91+
log2(e)
92+
*/
93+
const log2_e: f32 = 1.44269504088896340735992468100189214f32;
94+
95+
/*
96+
Const: log10_e
97+
98+
log10(e)
99+
*/
100+
const log10_e: f32 = 0.434294481903251827651128918916605082f32;
101+
102+
/*
103+
Const: ln_2
104+
105+
ln(2.0)
106+
*/
107+
const ln_2: f32 = 0.693147180559945309417232121458176568f32;
108+
109+
/*
110+
Const: ln_10
111+
112+
ln(10.0)
113+
*/
114+
const ln_10: f32 = 2.30258509299404568401799145468436421f32;
115+
}
116+
117+
//
118+
// Local Variables:
119+
// mode: rust
120+
// fill-column: 78;
121+
// indent-tabs-mode: nil
122+
// c-basic-offset: 4
123+
// buffer-file-coding-system: utf-8-unix
124+
// End:
125+
//

0 commit comments

Comments
 (0)