Skip to content

Commit c108db9

Browse files
authored
Merge pull request rust-lang#265 from ankane/no_panic
2 parents 2af4e21 + e4c6d24 commit c108db9

20 files changed

+26
-6
lines changed

src/math/acosh.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa3
77
/// Calculates the inverse hyperbolic cosine of `x`.
88
/// Is defined as `log(x + sqrt(x*x-1))`.
99
/// `x` must be a number greater than or equal to 1.
10+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
1011
pub fn acosh(x: f64) -> f64 {
1112
let u = x.to_bits();
1213
let e = ((u >> 52) as usize) & 0x7ff;

src/math/acoshf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const LN2: f32 = 0.693147180559945309417232121458176568;
77
/// Calculates the inverse hyperbolic cosine of `x`.
88
/// Is defined as `log(x + sqrt(x*x-1))`.
99
/// `x` must be a number greater than or equal to 1.
10+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
1011
pub fn acoshf(x: f32) -> f32 {
1112
let u = x.to_bits();
1213
let a = u & 0x7fffffff;

src/math/asinh.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa3
77
///
88
/// Calculates the inverse hyperbolic sine of `x`.
99
/// Is defined as `sgn(x)*log(|x|+sqrt(x*x+1))`.
10+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
1011
pub fn asinh(mut x: f64) -> f64 {
1112
let mut u = x.to_bits();
1213
let e = ((u >> 52) as usize) & 0x7ff;

src/math/asinhf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const LN2: f32 = 0.693147180559945309417232121458176568;
77
///
88
/// Calculates the inverse hyperbolic sine of `x`.
99
/// Is defined as `sgn(x)*log(|x|+sqrt(x*x+1))`.
10+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
1011
pub fn asinhf(mut x: f32) -> f32 {
1112
let u = x.to_bits();
1213
let i = u & 0x7fffffff;

src/math/atanh.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::log1p;
55
///
66
/// Calculates the inverse hyperbolic tangent of `x`.
77
/// Is defined as `log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2`.
8+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
89
pub fn atanh(x: f64) -> f64 {
910
let u = x.to_bits();
1011
let e = ((u >> 52) as usize) & 0x7ff;

src/math/atanhf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::log1pf;
55
///
66
/// Calculates the inverse hyperbolic tangent of `x`.
77
/// Is defined as `log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2`.
8+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
89
pub fn atanhf(mut x: f32) -> f32 {
910
let mut u = x.to_bits();
1011
let sign = (u >> 31) != 0;

src/math/copysign.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
///
33
/// Constructs a number with the magnitude (absolute value) of its
44
/// first argument, `x`, and the sign of its second argument, `y`.
5+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
56
pub fn copysign(x: f64, y: f64) -> f64 {
67
let mut ux = x.to_bits();
78
let uy = y.to_bits();

src/math/copysignf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
///
33
/// Constructs a number with the magnitude (absolute value) of its
44
/// first argument, `x`, and the sign of its second argument, `y`.
5+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
56
pub fn copysignf(x: f32, y: f32) -> f32 {
67
let mut ux = x.to_bits();
78
let uy = y.to_bits();

src/math/erf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ fn erfc2(ix: u32, mut x: f64) -> f64 {
219219
/// Calculates an approximation to the “error function”, which estimates
220220
/// the probability that an observation will fall within x standard
221221
/// deviations of the mean (assuming a normal distribution).
222+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
222223
pub fn erf(x: f64) -> f64 {
223224
let r: f64;
224225
let s: f64;

src/math/erff.rs

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ fn erfc2(mut ix: u32, mut x: f32) -> f32 {
130130
/// Calculates an approximation to the “error function”, which estimates
131131
/// the probability that an observation will fall within x standard
132132
/// deviations of the mean (assuming a normal distribution).
133+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
133134
pub fn erff(x: f32) -> f32 {
134135
let r: f32;
135136
let s: f32;

src/math/exp10.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ const P10: &[f64] = &[
66
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15,
77
];
88

9+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
910
pub fn exp10(x: f64) -> f64 {
1011
let (mut y, n) = modf(x);
1112
let u: u64 = n.to_bits();
1213
/* fabs(n) < 16 without raising invalid on nan */
1314
if (u >> 52 & 0x7ff) < 0x3ff + 4 {
1415
if y == 0.0 {
15-
return P10[((n as isize) + 15) as usize];
16+
return i!(P10, ((n as isize) + 15) as usize);
1617
}
1718
y = exp2(LN10 * y);
18-
return y * P10[((n as isize) + 15) as usize];
19+
return y * i!(P10, ((n as isize) + 15) as usize);
1920
}
2021
return pow(10.0, x);
2122
}

src/math/exp10f.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ const P10: &[f32] = &[
66
1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7,
77
];
88

9+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
910
pub fn exp10f(x: f32) -> f32 {
1011
let (mut y, n) = modff(x);
1112
let u = n.to_bits();
1213
/* fabsf(n) < 8 without raising invalid on nan */
1314
if (u >> 23 & 0xff) < 0x7f + 3 {
1415
if y == 0.0 {
15-
return P10[((n as isize) + 7) as usize];
16+
return i!(P10, ((n as isize) + 7) as usize);
1617
}
1718
y = exp2f(LN10_F32 * y);
18-
return y * P10[((n as isize) + 7) as usize];
19+
return y * i!(P10, ((n as isize) + 7) as usize);
1920
}
2021
return exp2(LN10_F64 * (x as f64)) as f32;
2122
}

src/math/ilogb.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const FP_ILOGBNAN: i32 = -1 - 0x7fffffff;
22
const FP_ILOGB0: i32 = FP_ILOGBNAN;
33

4+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
45
pub fn ilogb(x: f64) -> i32 {
56
let mut i: u64 = x.to_bits();
67
let e = ((i >> 52) & 0x7ff) as i32;

src/math/ilogbf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const FP_ILOGBNAN: i32 = -1 - 0x7fffffff;
22
const FP_ILOGB0: i32 = FP_ILOGBNAN;
33

4+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
45
pub fn ilogbf(x: f32) -> i32 {
56
let mut i = x.to_bits();
67
let e = ((i >> 23) & 0xff) as i32;

src/math/lgamma.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::lgamma_r;
22

3+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
34
pub fn lgamma(x: f64) -> f64 {
45
lgamma_r(x).0
56
}

src/math/lgamma_r.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn sin_pi(mut x: f64) -> f64 {
152152
x = 2.0 * (x * 0.5 - floor(x * 0.5)); /* x mod 2.0 */
153153

154154
n = (x * 4.0) as i32;
155-
n = (n + 1) / 2;
155+
n = div!(n + 1, 2);
156156
x -= (n as f64) * 0.5;
157157
x *= PI;
158158

@@ -164,6 +164,7 @@ fn sin_pi(mut x: f64) -> f64 {
164164
}
165165
}
166166

167+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
167168
pub fn lgamma_r(mut x: f64) -> (f64, i32) {
168169
let u: u64 = x.to_bits();
169170
let mut t: f64;

src/math/lgammaf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::lgammaf_r;
22

3+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
34
pub fn lgammaf(x: f32) -> f32 {
45
lgammaf_r(x).0
56
}

src/math/lgammaf_r.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn sin_pi(mut x: f32) -> f32 {
8888
x = 2.0 * (x * 0.5 - floorf(x * 0.5)); /* x mod 2.0 */
8989

9090
n = (x * 4.0) as isize;
91-
n = (n + 1) / 2;
91+
n = div!(n + 1, 2);
9292
y = (x as f64) - (n as f64) * 0.5;
9393
y *= 3.14159265358979323846;
9494
match n {
@@ -99,6 +99,7 @@ fn sin_pi(mut x: f32) -> f32 {
9999
}
100100
}
101101

102+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
102103
pub fn lgammaf_r(mut x: f32) -> (f32, i32) {
103104
let u = x.to_bits();
104105
let mut t: f32;

src/math/sincos.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use super::{get_high_word, k_cos, k_sin, rem_pio2};
1414

15+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
1516
pub fn sincos(x: f64) -> (f64, f64) {
1617
let s: f64;
1718
let c: f64;

src/math/sincosf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const S2PIO2: f32 = 2.0 * PI_2; /* 0x400921FB, 0x54442D18 */
2323
const S3PIO2: f32 = 3.0 * PI_2; /* 0x4012D97C, 0x7F3321D2 */
2424
const S4PIO2: f32 = 4.0 * PI_2; /* 0x401921FB, 0x54442D18 */
2525

26+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2627
pub fn sincosf(x: f32) -> (f32, f32) {
2728
let s: f32;
2829
let c: f32;

0 commit comments

Comments
 (0)