Skip to content

Commit

Permalink
Test convertibles in std::isnan()
Browse files Browse the repository at this point in the history
  • Loading branch information
robincaloudis committed Jul 15, 2024
1 parent 41b2677 commit 4edaeb5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions libcxx/test/std/numerics/c.math/isnan.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,30 @@ struct TestInt {
}
};

struct ConvertibleFloat {
int value;
ConvertibleFloat(int v) : value(v) {}
operator float() const { return static_cast<float>(value); }
};

struct ConvertibleDouble {
int value;
ConvertibleDouble(int v) : value(v) {}
operator double() const { return static_cast<double>(value); }
};

struct ConvertibleLongDouble {
int value;
ConvertibleLongDouble(int v) : value(v) {}
operator long double() const { return static_cast<long double>(value); }
};

int main(int, char**) {
types::for_each(types::floating_point_types(), TestFloat());
types::for_each(types::integral_types(), TestInt());
assert(!std::isnan(ConvertibleFloat(0)));
assert(!std::isnan(ConvertibleDouble(0)));
assert(!std::isnan(ConvertibleLongDouble(0)));

return 0;
}

0 comments on commit 4edaeb5

Please sign in to comment.