From 5339f61ee4e56f7cfa7bfabef07d5bf66bfa3eb8 Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Thu, 9 May 2024 11:39:37 -0400 Subject: [PATCH] Support `QuantityPoint` in `isnan` (#236) Helps #221. --- au/math.hh | 6 ++++++ au/math_test.cc | 1 + 2 files changed, 7 insertions(+) diff --git a/au/math.hh b/au/math.hh index 34a194c3..feac9cb5 100644 --- a/au/math.hh +++ b/au/math.hh @@ -309,6 +309,12 @@ constexpr bool isnan(Quantity q) { return std::isnan(q.in(U{})); } +// Overload of `isnan` for `QuantityPoint`. +template +constexpr bool isnan(QuantityPoint p) { + return std::isnan(p.in(U{})); +} + // The maximum of two values of the same dimension. // // Unlike std::max, returns by value rather than by reference, because the types might differ. diff --git a/au/math_test.cc b/au/math_test.cc index 5b71b2a1..7a8dd2da 100644 --- a/au/math_test.cc +++ b/au/math_test.cc @@ -601,6 +601,7 @@ TEST(isnan, TransparentlyActsOnSameAsValue) { for (const double x : values) { EXPECT_EQ(isnan(meters(x)), std::isnan(x)); + EXPECT_EQ(isnan(meters_pt(x)), std::isnan(x)); EXPECT_EQ(isnan((radians / second)(x)), std::isnan(x)); } }