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

Add missing no_panic and inline annotations #207

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/math/acos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const QS3: f64 = -6.88283971605453293030e-01; /* 0xBFE6066C, 0x1B8D0159 */
const QS4: f64 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn r(z: f64) -> f64 {
let p: f64 = z * (PS0 + z * (PS1 + z * (PS2 + z * (PS3 + z * (PS4 + z * PS5)))));
let q: f64 = 1.0 + z * (QS1 + z * (QS2 + z * (QS3 + z * QS4)));
Expand Down
1 change: 1 addition & 0 deletions src/math/acosf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const P_S2: f32 = -8.6563630030e-03;
const Q_S1: f32 = -7.0662963390e-01;

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn r(z: f32) -> f32 {
let p = z * (P_S0 + z * (P_S1 + z * P_S2));
let q = 1. + z * Q_S1;
Expand Down
2 changes: 2 additions & 0 deletions src/math/acosh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa3
/// Calculates the inverse hyperbolic cosine of `x`.
/// Is defined as `log(x + sqrt(x*x-1))`.
/// `x` must be a number greater than or equal to 1.
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn acosh(x: f64) -> f64 {
let u = x.to_bits();
let e = ((u >> 52) as usize) & 0x7ff;
Expand Down
2 changes: 2 additions & 0 deletions src/math/acoshf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const LN2: f32 = 0.693147180559945309417232121458176568;
/// Calculates the inverse hyperbolic cosine of `x`.
/// Is defined as `log(x + sqrt(x*x-1))`.
/// `x` must be a number greater than or equal to 1.
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn acoshf(x: f32) -> f32 {
let u = x.to_bits();
let a = u & 0x7fffffff;
Expand Down
1 change: 1 addition & 0 deletions src/math/asin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const Q_S3: f64 = -6.88283971605453293030e-01; /* 0xBFE6066C, 0x1B8D0159 */
const Q_S4: f64 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn comp_r(z: f64) -> f64 {
let p = z * (P_S0 + z * (P_S1 + z * (P_S2 + z * (P_S3 + z * (P_S4 + z * P_S5)))));
let q = 1.0 + z * (Q_S1 + z * (Q_S2 + z * (Q_S3 + z * Q_S4)));
Expand Down
1 change: 1 addition & 0 deletions src/math/asinf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const P_S2: f32 = -8.6563630030e-03;
const Q_S1: f32 = -7.0662963390e-01;

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn r(z: f32) -> f32 {
let p = z * (P_S0 + z * (P_S1 + z * P_S2));
let q = 1. + z * Q_S1;
Expand Down
2 changes: 2 additions & 0 deletions src/math/asinh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa3
///
/// Calculates the inverse hyperbolic sine of `x`.
/// Is defined as `sgn(x)*log(|x|+sqrt(x*x+1))`.
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn asinh(mut x: f64) -> f64 {
let mut u = x.to_bits();
let e = ((u >> 52) as usize) & 0x7ff;
Expand Down
2 changes: 2 additions & 0 deletions src/math/asinhf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const LN2: f32 = 0.693147180559945309417232121458176568;
///
/// Calculates the inverse hyperbolic sine of `x`.
/// Is defined as `sgn(x)*log(|x|+sqrt(x*x+1))`.
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn asinhf(mut x: f32) -> f32 {
let u = x.to_bits();
let i = u & 0x7fffffff;
Expand Down
2 changes: 2 additions & 0 deletions src/math/atanh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use super::log1p;
///
/// Calculates the inverse hyperbolic tangent of `x`.
/// Is defined as `log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2`.
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn atanh(x: f64) -> f64 {
let u = x.to_bits();
let e = ((u >> 52) as usize) & 0x7ff;
Expand Down
2 changes: 2 additions & 0 deletions src/math/atanhf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use super::log1pf;
///
/// Calculates the inverse hyperbolic tangent of `x`.
/// Is defined as `log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2`.
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn atanhf(mut x: f32) -> f32 {
let mut u = x.to_bits();
let sign = (u >> 31) != 0;
Expand Down
2 changes: 2 additions & 0 deletions src/math/copysign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
///
/// Constructs a number with the magnitude (absolute value) of its
/// first argument, `x`, and the sign of its second argument, `y`.
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn copysign(x: f64, y: f64) -> f64 {
let mut ux = x.to_bits();
let uy = y.to_bits();
Expand Down
2 changes: 2 additions & 0 deletions src/math/copysignf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
///
/// Constructs a number with the magnitude (absolute value) of its
/// first argument, `x`, and the sign of its second argument, `y`.
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn copysignf(x: f32, y: f32) -> f32 {
let mut ux = x.to_bits();
let uy = y.to_bits();
Expand Down
6 changes: 6 additions & 0 deletions src/math/erf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const SB5: f64 = 2.55305040643316442583e+03; /* 0x40A3F219, 0xCEDF3BE6 */
const SB6: f64 = 4.74528541206955367215e+02; /* 0x407DA874, 0xE79FE763 */
const SB7: f64 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn erfc1(x: f64) -> f64 {
let s: f64;
let p: f64;
Expand All @@ -184,6 +185,7 @@ fn erfc1(x: f64) -> f64 {
1.0 - ERX - p / q
}

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn erfc2(ix: u32, mut x: f64) -> f64 {
let s: f64;
let r: f64;
Expand Down Expand Up @@ -219,6 +221,8 @@ fn erfc2(ix: u32, mut x: f64) -> f64 {
/// Calculates an approximation to the “error function”, which estimates
/// the probability that an observation will fall within x standard
/// deviations of the mean (assuming a normal distribution).
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn erf(x: f64) -> f64 {
let r: f64;
let s: f64;
Expand Down Expand Up @@ -268,6 +272,8 @@ pub fn erf(x: f64) -> f64 {
/// Is `1 - erf(x)`. Is computed directly, so that you can use it to avoid
/// the loss of precision that would result from subtracting
/// large probabilities (on large `x`) from 1.
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn erfc(x: f64) -> f64 {
let r: f64;
let s: f64;
Expand Down
6 changes: 6 additions & 0 deletions src/math/erff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const SB5: f32 = 2.5530502930e+03; /* 0x451f90ce */
const SB6: f32 = 4.7452853394e+02; /* 0x43ed43a7 */
const SB7: f32 = -2.2440952301e+01; /* 0xc1b38712 */

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn erfc1(x: f32) -> f32 {
let s: f32;
let p: f32;
Expand All @@ -94,6 +95,7 @@ fn erfc1(x: f32) -> f32 {
return 1.0 - ERX - p / q;
}

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn erfc2(mut ix: u32, mut x: f32) -> f32 {
let s: f32;
let r: f32;
Expand Down Expand Up @@ -130,6 +132,8 @@ fn erfc2(mut ix: u32, mut x: f32) -> f32 {
/// Calculates an approximation to the “error function”, which estimates
/// the probability that an observation will fall within x standard
/// deviations of the mean (assuming a normal distribution).
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn erff(x: f32) -> f32 {
let r: f32;
let s: f32;
Expand Down Expand Up @@ -179,6 +183,8 @@ pub fn erff(x: f32) -> f32 {
/// Is `1 - erf(x)`. Is computed directly, so that you can use it to avoid
/// the loss of precision that would result from subtracting
/// large probabilities (on large `x`) from 1.
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn erfcf(x: f32) -> f32 {
let r: f32;
let s: f32;
Expand Down
2 changes: 2 additions & 0 deletions src/math/exp10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const P10: &[f64] = &[
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15,
];

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn exp10(x: f64) -> f64 {
let (mut y, n) = modf(x);
let u: u64 = n.to_bits();
Expand Down
2 changes: 2 additions & 0 deletions src/math/exp10f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const P10: &[f32] = &[
1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7,
];

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn exp10f(x: f32) -> f32 {
let (mut y, n) = modff(x);
let u = n.to_bits();
Expand Down
2 changes: 2 additions & 0 deletions src/math/fma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct Num {
}

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn normalize(x: f64) -> Num {
let x1p63: f64 = f64::from_bits(0x43e0000000000000); // 0x1p63 === 2 ^ 63

Expand All @@ -31,6 +32,7 @@ fn normalize(x: f64) -> Num {
}

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn mul(x: u64, y: u64) -> (u64, u64) {
let t1: u64;
let t2: u64;
Expand Down
2 changes: 2 additions & 0 deletions src/math/frexp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn frexp(x: f64) -> (f64, i32) {
let mut y = x.to_bits();
let ee = ((y >> 52) & 0x7ff) as i32;
Expand Down
2 changes: 2 additions & 0 deletions src/math/frexpf.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn frexpf(x: f32) -> (f32, i32) {
let mut y = x.to_bits();
let ee: i32 = ((y >> 23) & 0xff) as i32;
Expand Down
1 change: 1 addition & 0 deletions src/math/hypot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::sqrt;
const SPLIT: f64 = 134217728. + 1.; // 0x1p27 + 1 === (2 ^ 27) + 1

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn sq(x: f64) -> (f64, f64) {
let xh: f64;
let xl: f64;
Expand Down
2 changes: 2 additions & 0 deletions src/math/ilogb.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const FP_ILOGBNAN: i32 = -1 - 0x7fffffff;
const FP_ILOGB0: i32 = FP_ILOGBNAN;

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn ilogb(x: f64) -> i32 {
let mut i: u64 = x.to_bits();
let e = ((i >> 52) & 0x7ff) as i32;
Expand Down
2 changes: 2 additions & 0 deletions src/math/ilogbf.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const FP_ILOGBNAN: i32 = -1 - 0x7fffffff;
const FP_ILOGB0: i32 = FP_ILOGBNAN;

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn ilogbf(x: f32) -> i32 {
let mut i = x.to_bits();
let e = ((i >> 23) & 0xff) as i32;
Expand Down
5 changes: 5 additions & 0 deletions src/math/j0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const INVSQRTPI: f64 = 5.64189583547756279280e-01; /* 0x3FE20DD7, 0x50429B6D */
const TPI: f64 = 6.36619772367581382433e-01; /* 0x3FE45F30, 0x6DC9C883 */

/* common method when |x|>=2 */
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn common(ix: u32, x: f64, y0: bool) -> f64 {
let s: f64;
let mut c: f64;
Expand Down Expand Up @@ -109,6 +110,8 @@ const S02: f64 = 1.16926784663337450260e-04; /* 0x3F1EA6D2, 0xDD57DBF4 */
const S03: f64 = 5.13546550207318111446e-07; /* 0x3EA13B54, 0xCE84D5A9 */
const S04: f64 = 1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn j0(mut x: f64) -> f64 {
let z: f64;
let r: f64;
Expand Down Expand Up @@ -162,6 +165,8 @@ const V02: f64 = 7.60068627350353253702e-05; /* 0x3F13ECBB, 0xF578C6C1 */
const V03: f64 = 2.59150851840457805467e-07; /* 0x3E91642D, 0x7FF202FD */
const V04: f64 = 4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn y0(x: f64) -> f64 {
let z: f64;
let u: f64;
Expand Down
7 changes: 7 additions & 0 deletions src/math/j0f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use super::{cosf, fabsf, logf, sinf, sqrtf};
const INVSQRTPI: f32 = 5.6418961287e-01; /* 0x3f106ebb */
const TPI: f32 = 6.3661974669e-01; /* 0x3f22f983 */

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn common(ix: u32, x: f32, y0: bool) -> f32 {
let z: f32;
let s: f32;
Expand Down Expand Up @@ -62,6 +63,8 @@ const S02: f32 = 1.1692678527e-04; /* 0x38f53697 */
const S03: f32 = 5.1354652442e-07; /* 0x3509daa6 */
const S04: f32 = 1.1661400734e-09; /* 0x30a045e8 */

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn j0f(mut x: f32) -> f32 {
let z: f32;
let r: f32;
Expand Down Expand Up @@ -107,6 +110,8 @@ const V02: f32 = 7.6006865129e-05; /* 0x389f65e0 */
const V03: f32 = 2.5915085189e-07; /* 0x348b216c */
const V04: f32 = 4.4111031494e-10; /* 0x2ff280c2 */

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn y0f(x: f32) -> f32 {
let z: f32;
let u: f32;
Expand Down Expand Up @@ -215,6 +220,7 @@ const PS2: [f32; 5] = [
1.4657617569e+01, /* 0x416a859a */
];

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn pzerof(x: f32) -> f32 {
let p: &[f32; 6];
let q: &[f32; 5];
Expand Down Expand Up @@ -327,6 +333,7 @@ const QS2: [f32; 6] = [
-5.3109550476e+00, /* 0xc0a9f358 */
];

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn qzerof(x: f32) -> f32 {
let p: &[f32; 6];
let q: &[f32; 6];
Expand Down
5 changes: 5 additions & 0 deletions src/math/j1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use super::{cos, fabs, get_high_word, get_low_word, log, sin, sqrt};
const INVSQRTPI: f64 = 5.64189583547756279280e-01; /* 0x3FE20DD7, 0x50429B6D */
const TPI: f64 = 6.36619772367581382433e-01; /* 0x3FE45F30, 0x6DC9C883 */

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn common(ix: u32, x: f64, y1: bool, sign: bool) -> f64 {
let z: f64;
let mut s: f64;
Expand Down Expand Up @@ -113,6 +114,8 @@ const S03: f64 = 1.17718464042623683263e-06; /* 0x3EB3BFF8, 0x333F8498 */
const S04: f64 = 5.04636257076217042715e-09; /* 0x3E35AC88, 0xC97DFF2C */
const S05: f64 = 1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn j1(x: f64) -> f64 {
let mut z: f64;
let r: f64;
Expand Down Expand Up @@ -158,6 +161,8 @@ const V0: [f64; 5] = [
1.66559246207992079114e-11, /* 0x3DB25039, 0xDACA772A */
];

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn y1(x: f64) -> f64 {
let z: f64;
let u: f64;
Expand Down
9 changes: 9 additions & 0 deletions src/math/j1f.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unused)]
/* origin: FreeBSD /usr/src/lib/msun/src/e_j1f.c */
/*
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
Expand All @@ -18,6 +19,8 @@ use super::{cosf, fabsf, logf, sinf, sqrtf};
const INVSQRTPI: f32 = 5.6418961287e-01; /* 0x3f106ebb */
const TPI: f32 = 6.3661974669e-01; /* 0x3f22f983 */

#[inline(always)]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn common(ix: u32, x: f32, y1: bool, sign: bool) -> f32 {
let z: f64;
let mut s: f64;
Expand Down Expand Up @@ -63,6 +66,8 @@ const S03: f32 = 1.1771846857e-06; /* 0x359dffc2 */
const S04: f32 = 5.0463624390e-09; /* 0x31ad6446 */
const S05: f32 = 1.2354227016e-11; /* 0x2d59567e */

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn j1f(x: f32) -> f32 {
let mut z: f32;
let r: f32;
Expand Down Expand Up @@ -107,6 +112,8 @@ const V0: [f32; 5] = [
1.6655924903e-11, /* 0x2d9281cf */
];

#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn y1f(x: f32) -> f32 {
let z: f32;
let u: f32;
Expand Down Expand Up @@ -214,6 +221,7 @@ const PS2: [f32; 5] = [
8.3646392822e+00, /* 0x4105d590 */
];

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn ponef(x: f32) -> f32 {
let p: &[f32; 6];
let q: &[f32; 5];
Expand Down Expand Up @@ -326,6 +334,7 @@ const QS2: [f32; 6] = [
-4.9594988823e+00, /* 0xc09eb437 */
];

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
fn qonef(x: f32) -> f32 {
let p: &[f32; 6];
let q: &[f32; 6];
Expand Down
Loading