File tree 3 files changed +74
-0
lines changed 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 52
52
#include < boost/decimal/detail/cmath/tanh.hpp>
53
53
#include < boost/decimal/detail/cmath/tgamma.hpp>
54
54
#include < boost/decimal/detail/cmath/trunc.hpp>
55
+ #include < boost/decimal/detail/cmath/nan.hpp>
55
56
#include < boost/decimal/numbers.hpp>
56
57
57
58
// Macros from 3.6.2
Original file line number Diff line number Diff line change
1
+ // Copyright 2023 Matt Borland
2
+ // Distributed under the Boost Software License, Version 1.0.
3
+ // https://www.boost.org/LICENSE_1_0.txt
4
+
5
+ #ifndef BOOST_DECIMAL_DETAIL_CMATH_NAN_HPP
6
+ #define BOOST_DECIMAL_DETAIL_CMATH_NAN_HPP
7
+
8
+ #include < boost/decimal/fwd.hpp>
9
+ #include < boost/decimal/detail/config.hpp>
10
+ #include < boost/decimal/detail/type_traits.hpp>
11
+ #include < boost/decimal/cstdlib.hpp>
12
+ #include < limits>
13
+
14
+ #if !defined(BOOST_DECIMAL_DISABLE_CLIB)
15
+
16
+ namespace boost {
17
+ namespace decimal {
18
+
19
+ namespace detail {
20
+
21
+ template <typename TargetDecimalType>
22
+ constexpr auto nan_impl (const char * arg) noexcept -> TargetDecimalType
23
+ {
24
+ char * endptr {};
25
+ const auto val {strtod_impl<TargetDecimalType>(arg, &endptr)};
26
+ return val & std::numeric_limits<TargetDecimalType>::quiet_NaN ();
27
+ }
28
+
29
+ } // namespace detail
30
+
31
+ constexpr auto nand32 (const char * arg) noexcept -> decimal32
32
+ {
33
+ return detail::nan_impl<decimal32>(arg);
34
+ }
35
+
36
+ template <typename Dec>
37
+ constexpr auto nan (const char * arg) noexcept -> Dec
38
+ {
39
+ return detail::nan_impl<Dec>(arg);
40
+ }
41
+
42
+ constexpr auto nand64 (const char * arg) noexcept -> decimal64
43
+ {
44
+ return detail::nan_impl<decimal64>(arg);
45
+ }
46
+
47
+ constexpr auto nand128 (const char * arg) noexcept -> decimal128
48
+ {
49
+ return detail::nan_impl<decimal128>(arg);
50
+ }
51
+
52
+ } // namespace decimal
53
+ } // namespace boost
54
+
55
+ #endif // #if !defined(BOOST_DECIMAL_DISABLE_CLIB)
56
+
57
+ #endif // BOOST_DECIMAL_DETAIL_CMATH_NAN_HPP
Original file line number Diff line number Diff line change @@ -1340,6 +1340,16 @@ void test_exp2()
1340
1340
BOOST_TEST_EQ (exp2 (-std::numeric_limits<T>::infinity ()), T (0 * dist (rng)));
1341
1341
}
1342
1342
1343
+ #if !defined(BOOST_DECIMAL_DISABLE_CLIB)
1344
+ template <typename T>
1345
+ void test_nan ()
1346
+ {
1347
+ BOOST_TEST (!isnan (nan <T>(" 1" ) & std::numeric_limits<T>::quiet_NaN ()));
1348
+ BOOST_TEST (!isnan (nan <T>(" 2" ) & std::numeric_limits<T>::quiet_NaN ()));
1349
+ BOOST_TEST (!isnan (nan <T>(" -1" ) & std::numeric_limits<T>::quiet_NaN ()));
1350
+ }
1351
+ #endif
1352
+
1343
1353
int main ()
1344
1354
{
1345
1355
test_fmax<decimal32>();
@@ -1448,5 +1458,11 @@ int main()
1448
1458
test_exp2<decimal32>();
1449
1459
test_exp2<decimal64>();
1450
1460
1461
+ #if !defined(BOOST_DECIMAL_DISABLE_CLIB)
1462
+ test_nan<decimal32>();
1463
+ test_nan<decimal64>();
1464
+ test_nan<decimal128>();
1465
+ #endif
1466
+
1451
1467
return boost::report_errors ();
1452
1468
}
You can’t perform that action at this time.
0 commit comments