Add no_std compatible ceil method (#18498)

# Objective


[`f32::ceil`](https://doc.rust-lang.org/std/primitive.f32.html#method.ceil)
is not available in `core`. We have `floor` in `bevy_math::ops`, but no
equivalent for `floor`.

## Solution

Add `ops::ceil` for `no_std` compatibility.
This commit is contained in:
Joona Aalto 2025-03-25 06:18:00 +02:00 committed by GitHub
parent 933752ad46
commit 206599adf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -34,5 +34,6 @@ disallowed-methods = [
{ path = "f32::copysign", reason = "use ops::copysign instead for no_std compatibility" },
{ path = "f32::round", reason = "use ops::round instead for no_std compatibility" },
{ path = "f32::floor", reason = "use ops::floor instead for no_std compatibility" },
{ path = "f32::ceil", reason = "use ops::ceil instead for no_std compatibility" },
{ path = "f32::fract", reason = "use ops::fract instead for no_std compatibility" },
]

View File

@ -510,6 +510,14 @@ mod libm_ops_for_no_std {
libm::floorf(x)
}
/// Returns the smallest integer greater than or equal to `x`.
///
/// Precision is specified when the `libm` feature is enabled.
#[inline(always)]
pub fn ceil(x: f32) -> f32 {
libm::ceilf(x)
}
/// Returns the fractional part of `x`.
///
/// This function always returns the precise result.
@ -581,6 +589,14 @@ mod std_ops_for_no_std {
f32::floor(x)
}
/// Returns the smallest integer greater than or equal to `x`.
///
/// This function always returns the precise result.
#[inline(always)]
pub fn ceil(x: f32) -> f32 {
f32::ceil(x)
}
/// Returns the fractional part of `x`.
///
/// This function always returns the precise result.