Skip to content

Commit

Permalink
Merge pull request #176 from itchyny/fix-modulo-nan
Browse files Browse the repository at this point in the history
Fix modulo operator on NaN to emit NaN
  • Loading branch information
MiSawa authored Feb 25, 2024
2 parents 1a37b3d + f99a92c commit e3251cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/intrinsic/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ fn modulo(lhs: Value, rhs: Value) -> Result<Value, QueryExecutionError> {
use Value::*;
Ok(match (lhs, rhs) {
(Number(lhs), Number(rhs)) => {
if lhs.is_nan() || rhs.is_nan() {
return Ok(Value::number(f64::NAN));
}
let rhs = number_to_i64(rhs);
if rhs == 0 {
return Err(QueryExecutionError::DivModByZero);
Expand Down
16 changes: 16 additions & 0 deletions tests/hand_written/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,22 @@ test!(
"#
);

test!(
modulo_nan,
r#"
(1, nan) % (1, nan) | isnan
"#,
r#"
null
"#,
r#"
false
true
true
true
"#
);

test!(
delete1,
r#"
Expand Down

0 comments on commit e3251cc

Please sign in to comment.