Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 2c9fd14

Browse files
committed
tests, fixes, format
1 parent b034304 commit 2c9fd14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4371
-4173
lines changed

build.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ mod musl_reference_tests {
4141
"rem_pio2.rs",
4242
"rem_pio2_large.rs",
4343
"rem_pio2f.rs",
44+
"remquo.rs",
45+
"remquof.rs",
46+
"lgamma.rs", // lgamma passed, lgamma_r has more than 1 result
47+
"lgammaf.rs", // lgammaf passed, lgammaf_r has more than 1 result
48+
"frexp.rs", // more than 1 result
49+
"frexpf.rs", // more than 1 result
50+
"sincos.rs", // more than 1 result
51+
"sincosf.rs", // more than 1 result
52+
"modf.rs", // more than 1 result
53+
"modff.rs", // more than 1 result
54+
"asinef.rs", // not exists
55+
"jn.rs", // passed, but very slow
56+
"jnf.rs", // passed, but very slow
4457
];
4558

4659
struct Function {
@@ -78,12 +91,9 @@ mod musl_reference_tests {
7891

7992
let contents = fs::read_to_string(file).unwrap();
8093
let mut functions = contents.lines().filter(|f| f.starts_with("pub fn"));
81-
let function_to_test = functions.next().unwrap();
82-
if functions.next().is_some() {
83-
panic!("more than one function in");
94+
while let Some(function_to_test) = functions.next() {
95+
math.push(parse(function_to_test));
8496
}
85-
86-
math.push(parse(function_to_test));
8797
}
8898

8999
// Generate a bunch of random inputs for each function. This will
@@ -330,7 +340,7 @@ mod musl_reference_tests {
330340
src.push_str(match function.ret {
331341
Ty::F32 => "if _eqf(output, f32::from_bits(*expected as u32)).is_ok() { continue }",
332342
Ty::F64 => "if _eq(output, f64::from_bits(*expected as u64)).is_ok() { continue }",
333-
Ty::I32 => "if output as i64 == expected { continue }",
343+
Ty::I32 => "if output as i64 == *expected { continue }",
334344
Ty::Bool => unreachable!(),
335345
});
336346

ci/run-docker.sh

100755100644
File mode changed.

ci/run.sh

100755100644
File mode changed.

src/math/acosh.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
use super::{log, log1p, sqrt};
2-
3-
const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa39ef*/
4-
5-
/* acosh(x) = log(x + sqrt(x*x-1)) */
6-
pub fn acosh(x: f64) -> f64 {
7-
let u = x.to_bits();
8-
let e = ((u >> 52) as usize) & 0x7ff;
9-
10-
/* x < 1 domain error is handled in the called functions */
11-
12-
if e < 0x3ff + 1 {
13-
/* |x| < 2, up to 2ulp error in [1,1.125] */
14-
return log1p(x-1.0+sqrt((x-1.0)*(x-1.0)+2.0*(x-1.0)));
15-
}
16-
if e < 0x3ff + 26 {
17-
/* |x| < 0x1p26 */
18-
return log(2.0*x-1.0/(x+sqrt(x*x-1.0)));
19-
}
20-
/* |x| >= 0x1p26 or nan */
21-
return log(x) + LN2;
22-
}
1+
use super::{log, log1p, sqrt};
2+
3+
const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa39ef*/
4+
5+
/* acosh(x) = log(x + sqrt(x*x-1)) */
6+
pub fn acosh(x: f64) -> f64 {
7+
let u = x.to_bits();
8+
let e = ((u >> 52) as usize) & 0x7ff;
9+
10+
/* x < 1 domain error is handled in the called functions */
11+
12+
if e < 0x3ff + 1 {
13+
/* |x| < 2, up to 2ulp error in [1,1.125] */
14+
return log1p(x - 1.0 + sqrt((x - 1.0) * (x - 1.0) + 2.0 * (x - 1.0)));
15+
}
16+
if e < 0x3ff + 26 {
17+
/* |x| < 0x1p26 */
18+
return log(2.0 * x - 1.0 / (x + sqrt(x * x - 1.0)));
19+
}
20+
/* |x| >= 0x1p26 or nan */
21+
return log(x) + LN2;
22+
}

src/math/acoshf.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
use super::{log1pf, logf, sqrtf};
2-
3-
const LN2: f32 = 0.693147180559945309417232121458176568;
4-
5-
/* acosh(x) = log(x + sqrt(x*x-1)) */
6-
pub fn acoshf(x: f32) -> f32 {
7-
let u = x.to_bits();
8-
let a = u & 0x7fffffff;
9-
10-
if a < 0x3f800000+(1<<23) {
11-
/* |x| < 2, invalid if x < 1 or nan */
12-
/* up to 2ulp error in [1,1.125] */
13-
return log1pf(x-1.0 + sqrtf((x-1.0)*(x-1.0)+2.0*(x-1.0)));
14-
}
15-
if a < 0x3f800000+(12<<23) {
16-
/* |x| < 0x1p12 */
17-
return logf(2.0*x - 1.0/(x+sqrtf(x*x-1.0)));
18-
}
19-
/* x >= 0x1p12 */
20-
return logf(x) + LN2;
21-
}
1+
use super::{log1pf, logf, sqrtf};
2+
3+
const LN2: f32 = 0.693147180559945309417232121458176568;
4+
5+
/* acosh(x) = log(x + sqrt(x*x-1)) */
6+
pub fn acoshf(x: f32) -> f32 {
7+
let u = x.to_bits();
8+
let a = u & 0x7fffffff;
9+
10+
if a < 0x3f800000 + (1 << 23) {
11+
/* |x| < 2, invalid if x < 1 or nan */
12+
/* up to 2ulp error in [1,1.125] */
13+
return log1pf(x - 1.0 + sqrtf((x - 1.0) * (x - 1.0) + 2.0 * (x - 1.0)));
14+
}
15+
if a < 0x3f800000 + (12 << 23) {
16+
/* |x| < 0x1p12 */
17+
return logf(2.0 * x - 1.0 / (x + sqrtf(x * x - 1.0)));
18+
}
19+
/* x >= 0x1p12 */
20+
return logf(x) + LN2;
21+
}

src/math/asinef.rs

Lines changed: 93 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,93 @@
1-
/* @(#)z_asinef.c 1.0 98/08/13 */
2-
/******************************************************************
3-
* The following routines are coded directly from the algorithms
4-
* and coefficients given in "Software Manual for the Elementary
5-
* Functions" by William J. Cody, Jr. and William Waite, Prentice
6-
* Hall, 1980.
7-
******************************************************************/
8-
/******************************************************************
9-
* Arcsine
10-
*
11-
* Input:
12-
* x - floating point value
13-
* acosine - indicates acos calculation
14-
*
15-
* Output:
16-
* Arcsine of x.
17-
*
18-
* Description:
19-
* This routine calculates arcsine / arccosine.
20-
*
21-
*****************************************************************/
22-
23-
use super::{fabsf, sqrtf};
24-
25-
const P: [f32; 2] = [ 0.933935835, -0.504400557 ];
26-
const Q: [f32; 2] = [ 0.560363004e+1, -0.554846723e+1 ];
27-
const A: [f32; 2] = [ 0.0, 0.785398163 ];
28-
const B: [f32; 2] = [ 1.570796326, 0.785398163 ];
29-
const Z_ROOTEPS_F: f32 = 1.7263349182589107e-4;
30-
31-
pub fn asinef(x: f32, acosine: usize) -> f32
32-
{
33-
let flag: usize;
34-
let i: usize;
35-
let mut branch: bool = false;
36-
let g: f32;
37-
let mut res: f32 = 0.0;
38-
let mut y: f32;
39-
40-
/* Check for special values. */
41-
//i = numtestf (x);
42-
if x.is_nan() || x.is_infinite() {
43-
force_eval!(x);
44-
return x;
45-
}
46-
47-
y = fabsf(x);
48-
flag = acosine;
49-
50-
if y > 0.5 {
51-
i = 1 - flag;
52-
53-
/* Check for range error. */
54-
if y > 1.0 {
55-
return 0.0 / 0.0;
56-
}
57-
58-
g = (1.0 - y) / 2.0;
59-
y = -2.0 * sqrtf(g);
60-
branch = true;
61-
} else {
62-
i = flag;
63-
if y < Z_ROOTEPS_F {
64-
res = y;
65-
g = 0.0; // pleasing the uninitialized variable
66-
} else {
67-
g = y * y;
68-
}
69-
}
70-
71-
if y >= Z_ROOTEPS_F || branch {
72-
/* Calculate the Taylor series. */
73-
let p = (P[1] * g + P[0]) * g;
74-
let q = (g + Q[1]) * g + Q[0];
75-
let r = p / q;
76-
77-
res = y + y * r;
78-
}
79-
80-
/* Calculate asine or acose. */
81-
if flag == 0 {
82-
res = (A[i] + res) + A[i];
83-
if x < 0.0 {
84-
res = -res;
85-
}
86-
} else {
87-
if x < 0.0 {
88-
res = (B[i] + res) + B[i];
89-
} else {
90-
res = (A[i] - res) + A[i];
91-
}
92-
}
93-
94-
return res;
95-
}
1+
/* @(#)z_asinef.c 1.0 98/08/13 */
2+
/******************************************************************
3+
* The following routines are coded directly from the algorithms
4+
* and coefficients given in "Software Manual for the Elementary
5+
* Functions" by William J. Cody, Jr. and William Waite, Prentice
6+
* Hall, 1980.
7+
******************************************************************/
8+
/******************************************************************
9+
* Arcsine
10+
*
11+
* Input:
12+
* x - floating point value
13+
* acosine - indicates acos calculation
14+
*
15+
* Output:
16+
* Arcsine of x.
17+
*
18+
* Description:
19+
* This routine calculates arcsine / arccosine.
20+
*
21+
*****************************************************************/
22+
23+
use super::{fabsf, sqrtf};
24+
25+
const P: [f32; 2] = [ 0.933935835, -0.504400557 ];
26+
const Q: [f32; 2] = [ 0.560363004e+1, -0.554846723e+1 ];
27+
const A: [f32; 2] = [ 0.0, 0.785398163 ];
28+
const B: [f32; 2] = [ 1.570796326, 0.785398163 ];
29+
const Z_ROOTEPS_F: f32 = 1.7263349182589107e-4;
30+
31+
pub fn asinef(x: f32, acosine: bool) -> f32 {
32+
let i: usize;
33+
let mut branch: bool = false;
34+
let g: f32;
35+
let mut res: f32 = 0.0;
36+
let mut y: f32;
37+
38+
/* Check for special values. */
39+
//i = numtestf (x);
40+
if x.is_nan() || x.is_infinite() {
41+
force_eval!(x);
42+
return x;
43+
}
44+
45+
y = fabsf(x);
46+
let flag = acosine;
47+
48+
if y > 0.5 {
49+
i = (!flag) as usize;
50+
51+
/* Check for range error. */
52+
if y > 1.0 {
53+
return 0.0 / 0.0;
54+
}
55+
56+
g = (1.0 - y) / 2.0;
57+
y = -2.0 * sqrtf(g);
58+
branch = true;
59+
} else {
60+
i = flag;
61+
if y < Z_ROOTEPS_F {
62+
res = y;
63+
g = 0.0; // pleasing the uninitialized variable
64+
} else {
65+
g = y * y;
66+
}
67+
}
68+
69+
if y >= Z_ROOTEPS_F || branch {
70+
/* Calculate the Taylor series. */
71+
let p = (P[1] * g + P[0]) * g;
72+
let q = (g + Q[1]) * g + Q[0];
73+
let r = p / q;
74+
75+
res = y + y * r;
76+
}
77+
78+
/* Calculate asine or acose. */
79+
if flag == 0 {
80+
res = (A[i] + res) + A[i];
81+
if x < 0.0 {
82+
res = -res;
83+
}
84+
} else {
85+
if x < 0.0 {
86+
res = (B[i] + res) + B[i];
87+
} else {
88+
res = (A[i] - res) + A[i];
89+
}
90+
}
91+
92+
return res;
93+
}

src/math/asinh.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
use super::{log, log1p, sqrt};
2-
3-
const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa39ef*/
4-
5-
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
6-
pub fn asinh(mut x: f64) -> f64 {
7-
let mut u = x.to_bits();
8-
let e = ((u >> 52) as usize) & 0x7ff;
9-
let sign = (u >> 63) != 0;
10-
11-
/* |x| */
12-
u &= (!0) >> 1;
13-
x = f64::from_bits(u);
14-
15-
if e >= 0x3ff + 26 {
16-
/* |x| >= 0x1p26 or inf or nan */
17-
x = log(x) + LN2;
18-
} else if e >= 0x3ff + 1 {
19-
/* |x| >= 2 */
20-
x = log(2.0*x + 1.0/(sqrt(x*x+1.0)+x));
21-
} else if e >= 0x3ff - 26 {
22-
/* |x| >= 0x1p-26, up to 1.6ulp error in [0.125,0.5] */
23-
x = log1p(x + x*x/(sqrt(x*x+1.0)+1.0));
24-
} else {
25-
/* |x| < 0x1p-26, raise inexact if x != 0 */
26-
let x1p120 = f64::from_bits(0x4770000000000000);
27-
force_eval!(x + x1p120);
28-
}
29-
30-
if sign {
31-
-x
32-
} else {
33-
x
34-
}
35-
}
1+
use super::{log, log1p, sqrt};
2+
3+
const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa39ef*/
4+
5+
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
6+
pub fn asinh(mut x: f64) -> f64 {
7+
let mut u = x.to_bits();
8+
let e = ((u >> 52) as usize) & 0x7ff;
9+
let sign = (u >> 63) != 0;
10+
11+
/* |x| */
12+
u &= (!0) >> 1;
13+
x = f64::from_bits(u);
14+
15+
if e >= 0x3ff + 26 {
16+
/* |x| >= 0x1p26 or inf or nan */
17+
x = log(x) + LN2;
18+
} else if e >= 0x3ff + 1 {
19+
/* |x| >= 2 */
20+
x = log(2.0 * x + 1.0 / (sqrt(x * x + 1.0) + x));
21+
} else if e >= 0x3ff - 26 {
22+
/* |x| >= 0x1p-26, up to 1.6ulp error in [0.125,0.5] */
23+
x = log1p(x + x * x / (sqrt(x * x + 1.0) + 1.0));
24+
} else {
25+
/* |x| < 0x1p-26, raise inexact if x != 0 */
26+
let x1p120 = f64::from_bits(0x4770000000000000);
27+
force_eval!(x + x1p120);
28+
}
29+
30+
if sign {
31+
-x
32+
} else {
33+
x
34+
}
35+
}

0 commit comments

Comments
 (0)