fastmaths 0.1.0

High-performance no_std math routines targeting glibc parity and strict f64 accuracy.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Bit-level sign helpers: copysign and fabs.
//!
//! Implements sign injection and absolute value by masking the sign bit to
//! match IEEE-754 semantics, including signed zero handling.

use super::{f64_from_bits, f64_to_bits};

const SIGN_MASK: u64 = 0x8000_0000_0000_0000u64;

#[inline(always)]
pub fn copysign(x: f64, y: f64) -> f64 {
    f64_from_bits((f64_to_bits(x) & !SIGN_MASK) | (f64_to_bits(y) & SIGN_MASK))
}

#[inline(always)]
pub fn fabs(x: f64) -> f64 {
    f64_from_bits(f64_to_bits(x) & !SIGN_MASK)
}