Skip to content

Commit 63d50e9

Browse files
Merge pull request #640 from johnmcfarlane/numbers-not-math
Rename math to numbers - breaking change for user of math constants - in line with last-minute changes to equivalent C++20 feature - cnl/math.h -> cnl/numbers.h - `cnl::math` -> `cnl::numbers`
2 parents 40f3fae + 73fc579 commit 63d50e9

File tree

12 files changed

+233
-232
lines changed

12 files changed

+233
-232
lines changed

include/cnl/_impl/math_17.h include/cnl/_impl/numbers_17.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
// (See accompanying file ../LICENSE_1_0.txt or copy at
55
// http://www.boost.org/LICENSE_1_0.txt)
66

7-
#if !defined(CNL_IMPL_MATH_17_H)
8-
#define CNL_IMPL_MATH_17_H
7+
#if !defined(CNL_IMPL_NUMBERS_17_H)
8+
#define CNL_IMPL_NUMBERS_17_H
99

1010
#include "config.h"
1111

1212
/// compositional numeric library
1313
namespace cnl {
1414

1515
////////////////////////////////////////////////////////////////////////////////
16-
// cnl::math_constants
16+
// cnl::numbers
1717

1818
#if defined(__cpp_inline_variables)
1919
namespace _impl {
@@ -25,7 +25,7 @@ namespace cnl {
2525
CNL_NODISCARD constexpr T deleted_fn() = delete;
2626
}
2727

28-
namespace math {
28+
namespace numbers {
2929
/// partial implementation of [P0631](http://wg21.link/p0631)
3030

3131
// values taken from c++ (GCC) 7.2.0 implementation of math.h; disclaimer: may be a bit or two off

include/cnl/_impl/math_20.h include/cnl/_impl/numbers_20.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
///
1212
/// template<class T> concept floating_point = is_floating_point_v<T>;
1313

14-
#if !defined(CNL_IMPL_MATH_20_H)
15-
#define CNL_IMPL_MATH_20_H
14+
#if !defined(CNL_IMPL_NUMBERS_20_H)
15+
#define CNL_IMPL_NUMBERS_20_H
1616

1717
#if __has_include(<concepts>)
1818
#include <concepts>
@@ -28,7 +28,7 @@ namespace cnl {
2828
#endif
2929
}
3030

31-
namespace math {
31+
namespace numbers {
3232

3333
template<typename> inline constexpr bool __always_false = false;
3434

include/cnl/_impl/scaled_integer/constants.h include/cnl/_impl/scaled_integer/numbers.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "num_traits.h"
1414
#include "type.h"
1515

16-
#include "../../math.h"
16+
#include "../../numbers.h"
1717
#include "../used_digits.h"
1818

1919
/// compositional numeric library
@@ -91,7 +91,7 @@ namespace cnl {
9191
}
9292
}
9393

94-
namespace math {
94+
namespace numbers {
9595
/// specialization of \ref cnl::e for \ref cnl::scaled_integer
9696
template<typename Rep, int Exponent> inline constexpr scaled_integer<Rep, power<Exponent>> e_v<scaled_integer<Rep, power<Exponent>>> {
9797
_impl::constant_with_fallback<long double, Rep, Exponent>(e_v<long double>, _impl::e<Rep, Exponent>)

include/cnl/all.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@
110110
#include "fixed_point.h"
111111
#include "fraction.h"
112112
#include "limits.h" // NOLINT(modernize-deprecated-headers, hicpp-deprecated-headers)
113-
#include "math.h" // NOLINT(modernize-deprecated-headers, hicpp-deprecated-headers)
114113
#include "num_traits.h"
114+
#include "numbers.h"
115115
#include "numeric.h"
116116
#include "overflow.h"
117117
#include "overflow_integer.h"

include/cnl/math.h

-19
This file was deleted.

include/cnl/numbers.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
// Copyright John McFarlane 2019.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file ../LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
/// \file cnl/numbers.h
8+
/// \brief functions that might belong in the \verbatim<numbers>\endverbatim header
9+
10+
#if !defined(CNL_NUMBERS_H)
11+
#define CNL_NUMBERS_H
12+
13+
#if defined(__cpp_concepts)
14+
#include "_impl/numbers_20.h"
15+
#else
16+
#include "_impl/numbers_17.h"
17+
#endif
18+
19+
#endif // CNL_NUMBERS_H

include/cnl/scaled_integer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#if !defined(CNL_SCALED_INTEGER_H)
1111
#define CNL_SCALED_INTEGER_H
1212

13-
#include "_impl/scaled_integer/constants.h"
1413
#include "_impl/scaled_integer/convert_operator.h"
1514
#include "_impl/scaled_integer/declaration.h"
1615
#include "_impl/scaled_integer/extras.h"
@@ -21,6 +20,7 @@
2120
#include "_impl/scaled_integer/math.h"
2221
#include "_impl/scaled_integer/named.h"
2322
#include "_impl/scaled_integer/num_traits.h"
23+
#include "_impl/scaled_integer/numbers.h"
2424
#include "_impl/scaled_integer/operators.h"
2525
#include "_impl/scaled_integer/rep.h"
2626
#include "_impl/scaled_integer/set_rep.h"

test/unit/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ set(test_sources
1212
cstdint.cpp
1313
common.cpp
1414
limits.cpp
15-
math.cpp
1615
num_traits.cpp
1716
numeric.cpp
1817
number_test.cpp
18+
numbers.cpp
1919
overflow/overflow.cpp
2020
overflow/rounding/integer.cpp
2121
rounding/rounding.cpp
@@ -39,7 +39,7 @@ set(test_sources
3939
integer/type.cpp
4040
scaled_integer/scaled_integer_built_in.cpp
4141
scaled_integer/decimal.cpp
42-
scaled_integer/constants.cpp
42+
scaled_integer/numbers.cpp
4343
fraction/ctors.cpp
4444
fraction/fraction.cpp
4545
elastic_integer/elastic_integer.cpp

test/unit/math.cpp test/unit/numbers.cpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
// (See accompanying file ../LICENSE_1_0.txt or copy at
55
// http://www.boost.org/LICENSE_1_0.txt)
66

7+
#include <cnl/numbers.h>
8+
79
#include <cnl/_impl/type_traits/identical.h>
810
#include <cnl/constant.h>
9-
#include <cnl/math.h>
1011

1112
#include <gtest/gtest.h>
1213

@@ -15,7 +16,7 @@
1516
namespace {
1617
#if defined(__cpp_inline_variables)
1718

18-
namespace test_math_constants {
19+
namespace test_numbers {
1920
template<typename T>
2021
void test_type()
2122
{
@@ -25,19 +26,19 @@ namespace {
2526
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
2627
#define CNL_EXPECT_NEAR(expected, actual, epsilon) EXPECT_NEAR(double(expected), double(actual), double(epsilon))
2728

28-
CNL_EXPECT_NEAR(std::exp(T{1}), cnl::math::e_v<T>, epsilon);
29-
EXPECT_EQ(std::log2(cnl::math::e_v<T>), cnl::math::log2e_v<T>);
30-
CNL_EXPECT_NEAR(std::log10(cnl::math::e_v<T>), cnl::math::log10e_v<T>, epsilon);
31-
CNL_EXPECT_NEAR(std::atan(T{1})*T{4}, cnl::math::pi_v<T>, epsilon);
32-
CNL_EXPECT_NEAR(T{1}/cnl::math::pi_v<T>, cnl::math::inv_pi_v<T>, epsilon);
33-
CNL_EXPECT_NEAR(T{1}/std::sqrt(cnl::math::pi_v<T>), cnl::math::inv_sqrtpi_v<T>, epsilon);
34-
CNL_EXPECT_NEAR(std::log(T{2}), cnl::math::ln2_v<T>, epsilon);
35-
CNL_EXPECT_NEAR(std::log(T{10}), cnl::math::ln10_v<T>, epsilon);
36-
CNL_EXPECT_NEAR(std::sqrt(T{2}), cnl::math::sqrt2_v<T>, epsilon);
37-
CNL_EXPECT_NEAR(std::sqrt(T{3}), cnl::math::sqrt3_v<T>, epsilon);
38-
CNL_EXPECT_NEAR(T{1}/cnl::math::sqrt3_v<T>, cnl::math::inv_sqrt3_v<T>, epsilon);
39-
CNL_EXPECT_NEAR(0.5772156649015328606065120900824024L, cnl::math::egamma_v<T>, epsilon);
40-
CNL_EXPECT_NEAR(1.6180339887498948482045868343656381L, cnl::math::phi_v<T>, epsilon);
29+
CNL_EXPECT_NEAR(std::exp(T{1}), cnl::numbers::e_v<T>, epsilon);
30+
EXPECT_EQ(std::log2(cnl::numbers::e_v<T>), cnl::numbers::log2e_v<T>);
31+
CNL_EXPECT_NEAR(std::log10(cnl::numbers::e_v<T>), cnl::numbers::log10e_v<T>, epsilon);
32+
CNL_EXPECT_NEAR(std::atan(T{1})*T{4}, cnl::numbers::pi_v<T>, epsilon);
33+
CNL_EXPECT_NEAR(T{1}/cnl::numbers::pi_v<T>, cnl::numbers::inv_pi_v<T>, epsilon);
34+
CNL_EXPECT_NEAR(T{1}/std::sqrt(cnl::numbers::pi_v<T>), cnl::numbers::inv_sqrtpi_v<T>, epsilon);
35+
CNL_EXPECT_NEAR(std::log(T{2}), cnl::numbers::ln2_v<T>, epsilon);
36+
CNL_EXPECT_NEAR(std::log(T{10}), cnl::numbers::ln10_v<T>, epsilon);
37+
CNL_EXPECT_NEAR(std::sqrt(T{2}), cnl::numbers::sqrt2_v<T>, epsilon);
38+
CNL_EXPECT_NEAR(std::sqrt(T{3}), cnl::numbers::sqrt3_v<T>, epsilon);
39+
CNL_EXPECT_NEAR(T{1}/cnl::numbers::sqrt3_v<T>, cnl::numbers::inv_sqrt3_v<T>, epsilon);
40+
CNL_EXPECT_NEAR(0.5772156649015328606065120900824024L, cnl::numbers::egamma_v<T>, epsilon);
41+
CNL_EXPECT_NEAR(1.6180339887498948482045868343656381L, cnl::numbers::phi_v<T>, epsilon);
4142
}
4243

4344
TEST(numeric, float_constants) // NOLINT

test/unit/scaled_integer/constants.cpp

-184
This file was deleted.

0 commit comments

Comments
 (0)