Adjust ceil style to be more similar to floor
This commit is contained in:
parent
6a8bb0fa80
commit
3ae70a4a6c
2 changed files with 10 additions and 4 deletions
|
|
@ -67,6 +67,8 @@ no_mangle! {
|
|||
cbrtf(x: f32) -> f32;
|
||||
ceil(x: f64) -> f64;
|
||||
ceilf(x: f32) -> f32;
|
||||
ceilf128(x: f128) -> f128;
|
||||
ceilf16(x: f16) -> f16;
|
||||
copysign(x: f64, y: f64) -> f64;
|
||||
copysignf(x: f32, y: f32) -> f32;
|
||||
copysignf128(x: f128, y: f128) -> f128;
|
||||
|
|
|
|||
|
|
@ -31,24 +31,28 @@ pub fn ceil<F: Float>(x: F) -> F {
|
|||
|
||||
// Otherwise, raise an inexact exception.
|
||||
force_eval!(x + F::MAX);
|
||||
|
||||
if x.is_sign_positive() {
|
||||
ix += m;
|
||||
}
|
||||
|
||||
ix &= !m;
|
||||
F::from_bits(ix)
|
||||
} else {
|
||||
// |x| < 1.0, raise an inexact exception since truncation will happen (unless x == 0).
|
||||
force_eval!(x + F::MAX);
|
||||
|
||||
if x.is_sign_negative() {
|
||||
// -1.0 < x <= -0.0; rounding up goes toward -0.0.
|
||||
return F::NEG_ZERO;
|
||||
F::NEG_ZERO
|
||||
} else if ix << 1 != zero {
|
||||
// 0.0 < x < 1.0; rounding up goes toward +1.0.
|
||||
return F::ONE;
|
||||
F::ONE
|
||||
} else {
|
||||
// +0.0 remains unchanged
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
F::from_bits(ix)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue