Trevor Gross ecf6d3c6ce Simplify the configuration for no-panic
Currently, attributes for `no-panic` are gated behind both the `test`
config and `assert_no_panic`, because `no-panic` is a dev dependency (so
only available with test configuration). However, we only emit
`assert_no_panic` when the test config is also set anyway, so there
isn't any need to gate on both.

Replace gates on `all(test, assert_no_panic)` with only
`assert_no_panic`. This is simpler, and also has the benefit that
attempting to check for panics without `--test` errors.
2025-07-30 10:02:34 -05:00

15 lines
531 B
Rust

use super::expf;
/* k is such that k*ln2 has minimal relative error and x - kln2 > log(FLT_MIN) */
const K: i32 = 235;
/* expf(x)/2 for x >= log(FLT_MAX), slightly better than 0.5f*expf(x/2)*expf(x/2) */
#[cfg_attr(assert_no_panic, no_panic::no_panic)]
pub(crate) fn k_expo2f(x: f32) -> f32 {
let k_ln2 = f32::from_bits(0x4322e3bc);
/* note that k is odd and scale*scale overflows */
let scale = f32::from_bits(((0x7f + K / 2) as u32) << 23);
/* exp(x - k ln2) * 2**(k-1) */
expf(x - k_ln2) * scale * scale
}