mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
floatUtils_test.cpp
Go to the documentation of this file.
1/** \file floatUtils_test.cpp
2 * \brief Tests of floating-point classification utilities.
3 */
4
5#include "../../catch2/catch.hpp"
6
8
9#include <limits>
10
11/// Verify floating-point classification for finite and nonfinite values.
12/** Exercises the NaN and finite-value classifiers for float, double, and long double.
13 * The same test applies to standard and fast-math builds.
14 */
15/**
16 * \ingroup floatUtils_unit_tests
17 */
18TEST_CASE( "Floating-point classification handles finite and nonfinite values", "[math::floatUtils]" )
19{
20 REQUIRE( mx::math::isFinite( std::numeric_limits<float>::max() ) );
21 REQUIRE_FALSE( mx::math::isFinite( std::numeric_limits<float>::infinity() ) );
22 REQUIRE( mx::math::isNan( std::numeric_limits<float>::quiet_NaN() ) );
23 REQUIRE_FALSE( mx::math::isNan( std::numeric_limits<float>::infinity() ) );
24
25 REQUIRE( mx::math::isFinite( std::numeric_limits<double>::max() ) );
26 REQUIRE_FALSE( mx::math::isFinite( std::numeric_limits<double>::quiet_NaN() ) );
27 REQUIRE( mx::math::isNan( std::numeric_limits<double>::quiet_NaN() ) );
28 REQUIRE_FALSE( mx::math::isNan( std::numeric_limits<double>::infinity() ) );
29
30 REQUIRE( mx::math::isFinite( std::numeric_limits<long double>::max() ) );
31 REQUIRE_FALSE( mx::math::isFinite( std::numeric_limits<long double>::infinity() ) );
32 REQUIRE( mx::math::isNan( std::numeric_limits<long double>::quiet_NaN() ) );
33 REQUIRE_FALSE( mx::math::isNan( std::numeric_limits<long double>::infinity() ) );
34}
Floating-point classification utilities that remain reliable under fast-math optimization.
TEST_CASE("Floating-point classification handles finite and nonfinite values", "[math::floatUtils]")
Verify floating-point classification for finite and nonfinite values.
bool isNan(realT value)
Test whether a floating-point value is NaN, including under finite-math-only optimization.
bool isFinite(realT value)
Test whether a floating-point value is finite, including under finite-math-only optimization.