Skip to content

Commit 39f4714

Browse files
committed
fix: make NaN == NaN inside Expression
This is the easiest way to resolve #316 in a way that doesn't break the API (the other way being to use `OrderedFloat`).
1 parent eec9738 commit 39f4714

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Seeds for failure cases proptest has generated in the past. It is
2+
# automatically read and these particular cases re-run before any
3+
# novel cases are generated.
4+
#
5+
# It is recommended to check this file in to source control so that
6+
# everyone who runs the test benefits from these saved cases.
7+
cc 0c84b97c710f57935dd9b81feff3bd3c65662286d475e4d0c02c5b89c4911e9a # shrinks to e = Infix(InfixExpression { left: Address(MemoryReference { name: "aa", index: 0 }), operator: Slash, right: Infix(InfixExpression { left: PiConstant, operator: Minus, right: PiConstant }) })

quil-rs/src/expression/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ impl PartialEq for Expression {
115115
match (self, other) {
116116
(Self::Address(left), Self::Address(right)) => left == right,
117117
(Self::Infix(left), Self::Infix(right)) => left == right,
118-
(Self::Number(left), Self::Number(right)) => left == right,
118+
(Self::Number(left), Self::Number(right)) => {
119+
(left.re == right.re || left.re.is_nan() && right.re.is_nan()) && (left.im == right.im || left.im.is_nan() && right.im.is_nan())
120+
},
119121
(Self::Prefix(left), Self::Prefix(right)) => left == right,
120122
(Self::FunctionCall(left), Self::FunctionCall(right)) => left == right,
121123
(Self::Variable(left), Self::Variable(right)) => left == right,
@@ -990,6 +992,7 @@ mod tests {
990992
prop_assert!(p.is_ok());
991993
let p = p.unwrap();
992994
let simple_p = p.clone().into_simplified();
995+
993996
prop_assert_eq!(
994997
simple_p.clone(),
995998
simple_e.clone(),
@@ -1018,13 +1021,21 @@ mod tests {
10181021
assert_eq!(input, &restring);
10191022
}
10201023
}
1024+
1025+
#[test]
1026+
fn test_nan_is_equal() {
1027+
let left = Expression::Number(f64::NAN.into());
1028+
let right = left.clone();
1029+
assert_eq!(left, right);
1030+
}
10211031

10221032
#[test]
10231033
fn specific_simplification_tests() {
10241034
for (input, expected) in vec![
10251035
("pi", Expression::Number(PI.into())),
10261036
("pi/2", Expression::Number((PI / 2.0).into())),
10271037
("pi * pi", Expression::Number((PI.powi(2)).into())),
1038+
("1.0/(1.0-1.0)", Expression::Number(f64::NAN.into())),
10281039
(
10291040
"(a[0]*2*pi)/6.283185307179586",
10301041
Expression::Address(MemoryReference {

0 commit comments

Comments
 (0)