Skip to content

Commit

Permalink
Merge pull request #640 from johnmcfarlane/numbers-not-math
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
johnmcfarlane committed Aug 25, 2020
2 parents 40f3fae + 73fc579 commit 63d50e9
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 232 deletions.
Expand Up @@ -4,16 +4,16 @@
// (See accompanying file ../LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#if !defined(CNL_IMPL_MATH_17_H)
#define CNL_IMPL_MATH_17_H
#if !defined(CNL_IMPL_NUMBERS_17_H)
#define CNL_IMPL_NUMBERS_17_H

#include "config.h"

/// compositional numeric library
namespace cnl {

////////////////////////////////////////////////////////////////////////////////
// cnl::math_constants
// cnl::numbers

#if defined(__cpp_inline_variables)
namespace _impl {
Expand All @@ -25,7 +25,7 @@ namespace cnl {
CNL_NODISCARD constexpr T deleted_fn() = delete;
}

namespace math {
namespace numbers {
/// partial implementation of [P0631](http://wg21.link/p0631)

// values taken from c++ (GCC) 7.2.0 implementation of math.h; disclaimer: may be a bit or two off
Expand Down
Expand Up @@ -11,8 +11,8 @@
///
/// template<class T> concept floating_point = is_floating_point_v<T>;

#if !defined(CNL_IMPL_MATH_20_H)
#define CNL_IMPL_MATH_20_H
#if !defined(CNL_IMPL_NUMBERS_20_H)
#define CNL_IMPL_NUMBERS_20_H

#if __has_include(<concepts>)
#include <concepts>
Expand All @@ -28,7 +28,7 @@ namespace cnl {
#endif
}

namespace math {
namespace numbers {

template<typename> inline constexpr bool __always_false = false;

Expand Down
Expand Up @@ -13,7 +13,7 @@
#include "num_traits.h"
#include "type.h"

#include "../../math.h"
#include "../../numbers.h"
#include "../used_digits.h"

/// compositional numeric library
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace cnl {
}
}

namespace math {
namespace numbers {
/// specialization of \ref cnl::e for \ref cnl::scaled_integer
template<typename Rep, int Exponent> inline constexpr scaled_integer<Rep, power<Exponent>> e_v<scaled_integer<Rep, power<Exponent>>> {
_impl::constant_with_fallback<long double, Rep, Exponent>(e_v<long double>, _impl::e<Rep, Exponent>)
Expand Down
2 changes: 1 addition & 1 deletion include/cnl/all.h
Expand Up @@ -110,8 +110,8 @@
#include "fixed_point.h"
#include "fraction.h"
#include "limits.h" // NOLINT(modernize-deprecated-headers, hicpp-deprecated-headers)
#include "math.h" // NOLINT(modernize-deprecated-headers, hicpp-deprecated-headers)
#include "num_traits.h"
#include "numbers.h"
#include "numeric.h"
#include "overflow.h"
#include "overflow_integer.h"
Expand Down
19 changes: 0 additions & 19 deletions include/cnl/math.h

This file was deleted.

19 changes: 19 additions & 0 deletions include/cnl/numbers.h
@@ -0,0 +1,19 @@

// Copyright John McFarlane 2019.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file ../LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

/// \file cnl/numbers.h
/// \brief functions that might belong in the \verbatim<numbers>\endverbatim header

#if !defined(CNL_NUMBERS_H)
#define CNL_NUMBERS_H

#if defined(__cpp_concepts)
#include "_impl/numbers_20.h"
#else
#include "_impl/numbers_17.h"
#endif

#endif // CNL_NUMBERS_H
2 changes: 1 addition & 1 deletion include/cnl/scaled_integer.h
Expand Up @@ -10,7 +10,6 @@
#if !defined(CNL_SCALED_INTEGER_H)
#define CNL_SCALED_INTEGER_H

#include "_impl/scaled_integer/constants.h"
#include "_impl/scaled_integer/convert_operator.h"
#include "_impl/scaled_integer/declaration.h"
#include "_impl/scaled_integer/extras.h"
Expand All @@ -21,6 +20,7 @@
#include "_impl/scaled_integer/math.h"
#include "_impl/scaled_integer/named.h"
#include "_impl/scaled_integer/num_traits.h"
#include "_impl/scaled_integer/numbers.h"
#include "_impl/scaled_integer/operators.h"
#include "_impl/scaled_integer/rep.h"
#include "_impl/scaled_integer/set_rep.h"
Expand Down
4 changes: 2 additions & 2 deletions test/unit/CMakeLists.txt
Expand Up @@ -12,10 +12,10 @@ set(test_sources
cstdint.cpp
common.cpp
limits.cpp
math.cpp
num_traits.cpp
numeric.cpp
number_test.cpp
numbers.cpp
overflow/overflow.cpp
overflow/rounding/integer.cpp
rounding/rounding.cpp
Expand All @@ -39,7 +39,7 @@ set(test_sources
integer/type.cpp
scaled_integer/scaled_integer_built_in.cpp
scaled_integer/decimal.cpp
scaled_integer/constants.cpp
scaled_integer/numbers.cpp
fraction/ctors.cpp
fraction/fraction.cpp
elastic_integer/elastic_integer.cpp
Expand Down
31 changes: 16 additions & 15 deletions test/unit/math.cpp → test/unit/numbers.cpp
Expand Up @@ -4,9 +4,10 @@
// (See accompanying file ../LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <cnl/numbers.h>

#include <cnl/_impl/type_traits/identical.h>
#include <cnl/constant.h>
#include <cnl/math.h>

#include <gtest/gtest.h>

Expand All @@ -15,7 +16,7 @@
namespace {
#if defined(__cpp_inline_variables)

namespace test_math_constants {
namespace test_numbers {
template<typename T>
void test_type()
{
Expand All @@ -25,19 +26,19 @@ namespace {
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define CNL_EXPECT_NEAR(expected, actual, epsilon) EXPECT_NEAR(double(expected), double(actual), double(epsilon))

CNL_EXPECT_NEAR(std::exp(T{1}), cnl::math::e_v<T>, epsilon);
EXPECT_EQ(std::log2(cnl::math::e_v<T>), cnl::math::log2e_v<T>);
CNL_EXPECT_NEAR(std::log10(cnl::math::e_v<T>), cnl::math::log10e_v<T>, epsilon);
CNL_EXPECT_NEAR(std::atan(T{1})*T{4}, cnl::math::pi_v<T>, epsilon);
CNL_EXPECT_NEAR(T{1}/cnl::math::pi_v<T>, cnl::math::inv_pi_v<T>, epsilon);
CNL_EXPECT_NEAR(T{1}/std::sqrt(cnl::math::pi_v<T>), cnl::math::inv_sqrtpi_v<T>, epsilon);
CNL_EXPECT_NEAR(std::log(T{2}), cnl::math::ln2_v<T>, epsilon);
CNL_EXPECT_NEAR(std::log(T{10}), cnl::math::ln10_v<T>, epsilon);
CNL_EXPECT_NEAR(std::sqrt(T{2}), cnl::math::sqrt2_v<T>, epsilon);
CNL_EXPECT_NEAR(std::sqrt(T{3}), cnl::math::sqrt3_v<T>, epsilon);
CNL_EXPECT_NEAR(T{1}/cnl::math::sqrt3_v<T>, cnl::math::inv_sqrt3_v<T>, epsilon);
CNL_EXPECT_NEAR(0.5772156649015328606065120900824024L, cnl::math::egamma_v<T>, epsilon);
CNL_EXPECT_NEAR(1.6180339887498948482045868343656381L, cnl::math::phi_v<T>, epsilon);
CNL_EXPECT_NEAR(std::exp(T{1}), cnl::numbers::e_v<T>, epsilon);
EXPECT_EQ(std::log2(cnl::numbers::e_v<T>), cnl::numbers::log2e_v<T>);
CNL_EXPECT_NEAR(std::log10(cnl::numbers::e_v<T>), cnl::numbers::log10e_v<T>, epsilon);
CNL_EXPECT_NEAR(std::atan(T{1})*T{4}, cnl::numbers::pi_v<T>, epsilon);
CNL_EXPECT_NEAR(T{1}/cnl::numbers::pi_v<T>, cnl::numbers::inv_pi_v<T>, epsilon);
CNL_EXPECT_NEAR(T{1}/std::sqrt(cnl::numbers::pi_v<T>), cnl::numbers::inv_sqrtpi_v<T>, epsilon);
CNL_EXPECT_NEAR(std::log(T{2}), cnl::numbers::ln2_v<T>, epsilon);
CNL_EXPECT_NEAR(std::log(T{10}), cnl::numbers::ln10_v<T>, epsilon);
CNL_EXPECT_NEAR(std::sqrt(T{2}), cnl::numbers::sqrt2_v<T>, epsilon);
CNL_EXPECT_NEAR(std::sqrt(T{3}), cnl::numbers::sqrt3_v<T>, epsilon);
CNL_EXPECT_NEAR(T{1}/cnl::numbers::sqrt3_v<T>, cnl::numbers::inv_sqrt3_v<T>, epsilon);
CNL_EXPECT_NEAR(0.5772156649015328606065120900824024L, cnl::numbers::egamma_v<T>, epsilon);
CNL_EXPECT_NEAR(1.6180339887498948482045868343656381L, cnl::numbers::phi_v<T>, epsilon);
}

TEST(numeric, float_constants) // NOLINT
Expand Down
184 changes: 0 additions & 184 deletions test/unit/scaled_integer/constants.cpp

This file was deleted.

0 comments on commit 63d50e9

Please sign in to comment.