wowlab_engine_domain/
numeric.rs1pub(crate) const fn wrapping_i64_to_i32(value: i64) -> i32 {
4 let [byte_0, byte_1, byte_2, byte_3, _, _, _, _] = value.to_le_bytes();
5
6 i32::from_le_bytes([byte_0, byte_1, byte_2, byte_3])
7}
8
9#[expect(
10 clippy::cast_possible_truncation,
11 reason = "rotation action payloads deliberately use compact f32 values"
12)]
13pub(crate) const fn rotation_payload_f32(value: f64) -> f32 {
14 value as f32
16}
17
18#[cfg(test)]
19mod tests {
20 use googletest::prelude::*;
21
22 use super::*;
23
24 #[gtest]
25 fn explicit_width_conversions_preserve_current_boundary_semantics() {
26 expect_that!(wrapping_i64_to_i32(i64::from(i32::MAX) + 1), eq(i32::MIN));
27 expect_that!(wrapping_i64_to_i32(-1), eq(-1));
28 expect_that!(rotation_payload_f32(f64::NAN).is_nan(), is_true());
29 let positive_infinity = rotation_payload_f32(f64::INFINITY);
30
31 expect_that!(
32 positive_infinity.is_infinite() && positive_infinity.is_sign_positive(),
33 is_true()
34 );
35 }
36}