Skip to content

Commit 206599a

Browse files
authored
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.
1 parent 933752a commit 206599a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

crates/bevy_math/clippy.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ disallowed-methods = [
3434
{ path = "f32::copysign", reason = "use ops::copysign instead for no_std compatibility" },
3535
{ path = "f32::round", reason = "use ops::round instead for no_std compatibility" },
3636
{ path = "f32::floor", reason = "use ops::floor instead for no_std compatibility" },
37+
{ path = "f32::ceil", reason = "use ops::ceil instead for no_std compatibility" },
3738
{ path = "f32::fract", reason = "use ops::fract instead for no_std compatibility" },
3839
]

crates/bevy_math/src/ops.rs

+16
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,14 @@ mod libm_ops_for_no_std {
510510
libm::floorf(x)
511511
}
512512

513+
/// Returns the smallest integer greater than or equal to `x`.
514+
///
515+
/// Precision is specified when the `libm` feature is enabled.
516+
#[inline(always)]
517+
pub fn ceil(x: f32) -> f32 {
518+
libm::ceilf(x)
519+
}
520+
513521
/// Returns the fractional part of `x`.
514522
///
515523
/// This function always returns the precise result.
@@ -581,6 +589,14 @@ mod std_ops_for_no_std {
581589
f32::floor(x)
582590
}
583591

592+
/// Returns the smallest integer greater than or equal to `x`.
593+
///
594+
/// This function always returns the precise result.
595+
#[inline(always)]
596+
pub fn ceil(x: f32) -> f32 {
597+
f32::ceil(x)
598+
}
599+
584600
/// Returns the fractional part of `x`.
585601
///
586602
/// This function always returns the precise result.

0 commit comments

Comments
 (0)