Skip to content

Commit

Permalink
Add a test for various edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl authored Dec 12, 2024
1 parent c110c56 commit 0ad66e7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/engine/src/builtins/number/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,19 @@ pub(crate) fn f64_to_uint32(number: f64) -> u32 {
pub(crate) fn f64_to_uint32(number: f64) -> u32 {
f64_to_int32(number) as u32
}

#[test]
fn f64_to_int32_conversion() {
use crate::builtins::Number;

assert_eq!(f64_to_int32(0.0), 0);
assert_eq!(f64_to_int32(-0.0), 0);
assert_eq!(f64_to_int32(f64::NAN), 0);
assert_eq!(f64_to_int32(f64::INFINITY), 0);
assert_eq!(f64_to_int32(f64::NEG_INFINITY), 0);
assert_eq!(f64_to_int32((i64::from(i32::MAX) + 1) as f64), i32::MIN);
assert_eq!(f64_to_int32((i64::from(i32::MIN) - 1) as f64), i32::MAX);

assert_eq!(f64_to_int32(Number::MAX_SAFE_INTEGER + 1.0), 0);
assert_eq!(f64_to_int32(Number::MIN_SAFE_INTEGER - 1.0), 0);
}

0 comments on commit 0ad66e7

Please sign in to comment.