Skip to content

Commit add735e

Browse files
authored
Merge pull request rust-lang#264 from ankane/tgamma_no_panic
2 parents 1f7b8eb + 33ccb28 commit add735e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/math/tgamma.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn sinpi(mut x: f64) -> f64 {
3838

3939
/* reduce x into [-.25,.25] */
4040
n = (4.0 * x) as isize;
41-
n = (n + 1) / 2;
41+
n = div!(n + 1, 2);
4242
x -= (n as f64) * 0.5;
4343

4444
x *= PI;
@@ -118,18 +118,19 @@ fn s(x: f64) -> f64 {
118118
/* to avoid overflow handle large x differently */
119119
if x < 8.0 {
120120
for i in (0..=N).rev() {
121-
num = num * x + SNUM[i];
122-
den = den * x + SDEN[i];
121+
num = num * x + i!(SNUM, i);
122+
den = den * x + i!(SDEN, i);
123123
}
124124
} else {
125125
for i in 0..=N {
126-
num = num / x + SNUM[i];
127-
den = den / x + SDEN[i];
126+
num = num / x + i!(SNUM, i);
127+
den = den / x + i!(SDEN, i);
128128
}
129129
}
130130
return num / den;
131131
}
132132

133+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
133134
pub fn tgamma(mut x: f64) -> f64 {
134135
let u: u64 = x.to_bits();
135136
let absx: f64;
@@ -157,7 +158,7 @@ pub fn tgamma(mut x: f64) -> f64 {
157158
return 0.0 / 0.0;
158159
}
159160
if x <= FACT.len() as f64 {
160-
return FACT[(x as usize) - 1];
161+
return i!(FACT, (x as usize) - 1);
161162
}
162163
}
163164

src/math/tgammaf.rs

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

3+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
34
pub fn tgammaf(x: f32) -> f32 {
45
tgamma(x as f64) as f32
56
}

0 commit comments

Comments
 (0)