mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Complete removal of direct use of lexical_cast.
Correct silly typo in unchecked_factorial.hpp. Remove TEST_STD define in config.hpp as it needlessly breaks the TR1 tests. Remove lexical_cast.hpp workaround file. Correct #pragma in tr1.hpp.
This commit is contained in:
@@ -695,7 +695,7 @@ template <class T, int N>
|
||||
inline T unchecked_factorial_imp(unsigned i, const std::integral_constant<int, N>&)
|
||||
{
|
||||
static_assert(!std::is_integral<T>::value, "Type T must not be an integral type");
|
||||
static_assert(!std::numeric_limits<T>::is_integral, "Type T must not be an integral type");
|
||||
static_assert(!std::numeric_limits<T>::is_integer, "Type T must not be an integral type");
|
||||
// factorial<unsigned int>(n) is not implemented
|
||||
// because it would overflow integral type T for too small n
|
||||
// to be useful. Use instead a floating-point type,
|
||||
@@ -815,7 +815,7 @@ template <class T>
|
||||
inline T unchecked_factorial_imp(unsigned i, const std::integral_constant<int, 0>&)
|
||||
{
|
||||
static_assert(!std::is_integral<T>::value, "Type T must not be an integral type");
|
||||
static_assert(!std::numeric_limits<T>::is_integral, "Type T must not be an integral type");
|
||||
static_assert(!std::numeric_limits<T>::is_integer, "Type T must not be an integral type");
|
||||
// factorial<unsigned int>(n) is not implemented
|
||||
// because it would overflow integral type T for too small n
|
||||
// to be useful. Use instead a floating-point type,
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#define BOOST_MATH_NO_REAL_CONCEPT_TESTS
|
||||
#define BOOST_MATH_NO_DISTRIBUTION_CONCEPT_TESTS
|
||||
#define BOOST_MATH_NO_LEXICAL_CAST
|
||||
#define TEST_STD
|
||||
|
||||
// Since Boost.Multiprecision is in active development some tests do not fully cooperate yet.
|
||||
#define BOOST_MATH_NO_MP_TESTS
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
// (C) Copyright Matt Borland 2021 - 2022
|
||||
// Use, modification and distribution are subject to 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)
|
||||
|
||||
#ifndef BOOST_MATH_TOOLS_LEXICAL_CAST
|
||||
#define BOOST_MATH_TOOLS_LEXICAL_CAST
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <boost/math/tools/is_standalone.hpp>
|
||||
|
||||
#ifndef BOOST_MATH_STANDALONE
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#else
|
||||
|
||||
#ifndef BOOST_MATH_NO_LEXICAL_CAST
|
||||
#define BOOST_MATH_NO_LEXICAL_CAST
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <typename T, typename std::enable_if<std::is_same<T, float>::value, bool>::type = true>
|
||||
inline T lexical_cast(const char* s)
|
||||
{
|
||||
return std::strtof(s, nullptr);
|
||||
}
|
||||
|
||||
template <typename T, typename std::enable_if<std::is_same<T, double>::value, bool>::type = true>
|
||||
inline T lexical_cast(const char* s)
|
||||
{
|
||||
return std::strtod(s, nullptr);
|
||||
}
|
||||
|
||||
template <typename T, typename std::enable_if<std::is_same<T, long double>::value, bool>::type = true>
|
||||
inline T lexical_cast(const char* s)
|
||||
{
|
||||
return std::strtold(s, nullptr);
|
||||
}
|
||||
|
||||
template <typename T, typename std::enable_if<std::is_same<T, float>::value, bool>::type = true>
|
||||
inline T lexical_cast(const std::string& s)
|
||||
{
|
||||
return std::strtof(s.c_str(), nullptr);
|
||||
}
|
||||
|
||||
template <typename T, typename std::enable_if<std::is_same<T, double>::value, bool>::type = true>
|
||||
inline T lexical_cast(const std::string& s)
|
||||
{
|
||||
return std::strtod(s.c_str(), nullptr);
|
||||
}
|
||||
|
||||
template <typename T, typename std::enable_if<std::is_same<T, long double>::value, bool>::type = true>
|
||||
inline T lexical_cast(const std::string& s)
|
||||
{
|
||||
return std::strtold(s.c_str(), nullptr);
|
||||
}
|
||||
|
||||
template <typename T, typename T2, typename std::enable_if<(std::is_same<T, std::string>::value && std::is_arithmetic<T2>::value), bool>::type = true>
|
||||
inline T lexical_cast(const T2 v)
|
||||
{
|
||||
return std::to_string(v);
|
||||
}
|
||||
|
||||
}
|
||||
#endif // BOOST_MATH_STANDALONE
|
||||
#endif // BOOST_MATH_TOOLS_LEXICAL_CAST
|
||||
@@ -119,4 +119,22 @@ inline T create_test_value(largest_float, const char* str, const std::false_type
|
||||
std::integral_constant<bool, \
|
||||
std::is_constructible<T, const char*>::value>()\
|
||||
)
|
||||
|
||||
#if LDBL_MAX_10_EXP > DBL_MAX_10_EXP
|
||||
#define BOOST_MATH_TEST_HUGE_FLOAT_SUFFIX(x) BOOST_MATH_TEST_LARGEST_FLOAT_SUFFIX(x)
|
||||
#else
|
||||
#define BOOST_MATH_TEST_HUGE_FLOAT_SUFFIX(x) 0.0
|
||||
#endif
|
||||
|
||||
#define BOOST_MATH_HUGE_TEST_VALUE(T, x) create_test_value<T>(\
|
||||
BOOST_MATH_TEST_HUGE_FLOAT_SUFFIX(x),\
|
||||
#x,\
|
||||
std::integral_constant<bool, \
|
||||
std::numeric_limits<T>::is_specialized &&\
|
||||
(std::numeric_limits<T>::radix == 2)\
|
||||
&& (std::numeric_limits<T>::digits <= BOOST_MATH_TEST_LARGEST_FLOAT_DIGITS)\
|
||||
&& std::is_convertible<largest_float, T>::value>(),\
|
||||
std::integral_constant<bool, \
|
||||
std::is_constructible<T, const char*>::value>()\
|
||||
)
|
||||
#endif // TEST_VALUE_HPP
|
||||
|
||||
@@ -107,8 +107,8 @@ namespace boost{ namespace math{ namespace tr1{ extern "C"{
|
||||
# include <boost/config/auto_link.hpp>
|
||||
#endif
|
||||
#else // Standalone mode
|
||||
# ifdef _MSC_VER
|
||||
# __pragma("Auto linking of TR1 is not supported in standalone mode")
|
||||
# if defined(_MSC_VER) && !defined(BOOST_ALL_NO_LIB)
|
||||
# pragma message("Auto linking of TR1 is not supported in standalone mode")
|
||||
# endif
|
||||
#endif // BOOST_MATH_STANDALONE
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace boost{ namespace math{ namespace tr1{
|
||||
|
||||
extern "C" boost::long_long_type BOOST_MATH_TR1_DECL boost_llround BOOST_PREVENT_MACRO_SUBSTITUTION(double x) BOOST_MATH_C99_THROW_SPEC
|
||||
extern "C" long long BOOST_MATH_TR1_DECL boost_llround BOOST_PREVENT_MACRO_SUBSTITUTION(double x) BOOST_MATH_C99_THROW_SPEC
|
||||
{
|
||||
return c_policies::llround BOOST_PREVENT_MACRO_SUBSTITUTION(x);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace boost{ namespace math{ namespace tr1{
|
||||
|
||||
extern "C" boost::long_long_type BOOST_MATH_TR1_DECL boost_llroundf BOOST_PREVENT_MACRO_SUBSTITUTION(float x) BOOST_MATH_C99_THROW_SPEC
|
||||
extern "C" long long BOOST_MATH_TR1_DECL boost_llroundf BOOST_PREVENT_MACRO_SUBSTITUTION(float x) BOOST_MATH_C99_THROW_SPEC
|
||||
{
|
||||
return c_policies::llround BOOST_PREVENT_MACRO_SUBSTITUTION(x);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace boost{ namespace math{ namespace tr1{
|
||||
|
||||
extern "C" boost::long_long_type BOOST_MATH_TR1_DECL boost_llroundl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) BOOST_MATH_C99_THROW_SPEC
|
||||
extern "C" long long BOOST_MATH_TR1_DECL boost_llroundl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) BOOST_MATH_C99_THROW_SPEC
|
||||
{
|
||||
return c_policies::llround BOOST_PREVENT_MACRO_SUBSTITUTION(x);
|
||||
}
|
||||
|
||||
@@ -910,8 +910,6 @@ test-suite misc :
|
||||
../build//boost_math_c99
|
||||
../build//boost_math_c99f
|
||||
../../test/build//boost_unit_test_framework
|
||||
: : :
|
||||
[ check-target-builds ../config//is_ci_standalone_run "Standalone CI run" : <build>no ]
|
||||
]
|
||||
|
||||
[ run test_tr1.cpp
|
||||
@@ -921,7 +919,6 @@ test-suite misc :
|
||||
: : :
|
||||
<define>TEST_LD=1
|
||||
[ check-target-builds ../config//has_long_double_support "long double support" : : <build>no ]
|
||||
[ check-target-builds ../config//is_ci_standalone_run "Standalone CI run" : <build>no ]
|
||||
:
|
||||
test_tr1_long_double
|
||||
]
|
||||
@@ -933,7 +930,6 @@ test-suite misc :
|
||||
../build//boost_math_c99f
|
||||
../../test/build//boost_unit_test_framework
|
||||
: : : #requirements
|
||||
[ check-target-builds ../config//is_ci_standalone_run "Standalone CI run" : <build>no ]
|
||||
:
|
||||
test_tr1_c
|
||||
]
|
||||
@@ -945,7 +941,6 @@ test-suite misc :
|
||||
: : :
|
||||
<define>TEST_LD=1
|
||||
[ check-target-builds ../config//has_long_double_support "long double support" : : <build>no ]
|
||||
[ check-target-builds ../config//is_ci_standalone_run "Standalone CI run" : <build>no ]
|
||||
:
|
||||
test_tr1_c_long_double
|
||||
]
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_CXX11_TRAILING_RESULT_TYPES) && !defined(BOOST_NO_SFINAE_EXPR)
|
||||
|
||||
#include <boost/math/concepts/real_concept.hpp>
|
||||
#include <boost/math/tools/test_value.hpp>
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include <boost/test/tools/floating_point_comparison.hpp>
|
||||
#include <boost/math/quadrature/gauss_kronrod.hpp>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "test_autodiff.hpp"
|
||||
#include <boost/math/tools/test_value.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(test_autodiff_4)
|
||||
|
||||
@@ -72,9 +73,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(multiprecision, T, multiprecision_float_types) {
|
||||
const auto v =
|
||||
mixed_partials_f(w, x, y, z); // auto = autodiff_fvar<T,Nw,Nx,Ny,Nz>
|
||||
// Calculated from Mathematica symbolic differentiation.
|
||||
const T answer = boost::lexical_cast<T>(
|
||||
"1976.3196007477977177798818752904187209081211892187"
|
||||
"5499076582535951111845769110560421820940516423255314");
|
||||
const T answer = BOOST_MATH_TEST_VALUE(T, 1976.31960074779771777988187529041872090812118921875499076582535951111845769110560421820940516423255314);
|
||||
// BOOST_CHECK_CLOSE(v.derivative(Nw,Nx,Ny,Nz), answer, eps); // Doesn't work
|
||||
// for cpp_dec_float
|
||||
const T relative_error =
|
||||
|
||||
@@ -87,7 +87,7 @@ using boost::math::lambert_w0;
|
||||
#include "table_type.hpp"
|
||||
|
||||
#ifndef SC_
|
||||
# define SC_(x) boost::lexical_cast<typename table_type<T>::type>(BOOST_STRINGIZE(x))
|
||||
# define SC_(x) BOOST_MATH_HUGE_TEST_VALUE(typename table_type<T>::type, x)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include <boost/test/tools/floating_point_comparison.hpp>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/type_traits/is_constructible.hpp>
|
||||
|
||||
#ifdef BOOST_MATH_TEST_MULTIPRECISION
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <boost/test/tools/floating_point_comparison.hpp>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/type_traits/is_constructible.hpp>
|
||||
#include <boost/math/special_functions/fpclassify.hpp> // isnan, isfinite.
|
||||
#include <boost/math/special_functions/next.hpp> // float_next, float_prior
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <boost/test/tools/floating_point_comparison.hpp>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/type_traits/is_constructible.hpp>
|
||||
#include <boost/math/special_functions/fpclassify.hpp> // isnan, isfinite.
|
||||
#include <boost/math/special_functions/next.hpp> // float_next, float_prior
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <boost/test/tools/floating_point_comparison.hpp>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/type_traits/is_constructible.hpp>
|
||||
|
||||
#include <boost/multiprecision/float128.hpp>
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <boost/test/tools/floating_point_comparison.hpp>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/type_traits/is_constructible.hpp>
|
||||
#include <boost/math/special_functions/fpclassify.hpp> // isnan, isfinite.
|
||||
#include <boost/math/special_functions/next.hpp> // float_next, float_prior
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <boost/test/tools/floating_point_comparison.hpp>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/type_traits/is_constructible.hpp>
|
||||
#include <boost/multiprecision/cpp_bin_float.hpp>
|
||||
using boost::multiprecision::cpp_bin_float_quad;
|
||||
|
||||
@@ -336,7 +336,7 @@ void test_legendre_p_zeros()
|
||||
Real next_zero = zeros[k];
|
||||
BOOST_CHECK(next_zero > previous_zero);
|
||||
|
||||
std::string err = "Tolerance failed for (n, k) = (" + boost::lexical_cast<std::string>(n) + "," + boost::lexical_cast<std::string>(k) + ")\n";
|
||||
std::string err = "Tolerance failed for (n, k) = (" + std::to_string(n) + "," + std::to_string(k) + ")\n";
|
||||
if (n < 40)
|
||||
{
|
||||
BOOST_CHECK_MESSAGE( abs(legendre_p(n, next_zero)) < 100*tol,
|
||||
|
||||
@@ -104,8 +104,8 @@ void test_value(const T& val, const char* name)
|
||||
template <class T>
|
||||
void test_values(const T& val, const char* name)
|
||||
{
|
||||
static const T a = boost::lexical_cast<T>("1.3456724e22");
|
||||
static const T b = boost::lexical_cast<T>("1.3456724e-22");
|
||||
static const T a = T("1.3456724e22");
|
||||
static const T b = T("1.3456724e-22");
|
||||
static const T z = 0;
|
||||
static const T one = 1;
|
||||
static const T radix = std::numeric_limits<T>::radix;
|
||||
|
||||
@@ -41,6 +41,7 @@ using boost::math::owens_t;
|
||||
#include "libs/math/test/handle_test_result.hpp"
|
||||
#include "libs/math/test/table_type.hpp"
|
||||
#include "libs/math/test/functor.hpp"
|
||||
#include "boost/math/tools/test_value.hpp"
|
||||
#include "test_owens_t.hpp"
|
||||
|
||||
//
|
||||
@@ -52,19 +53,8 @@ using boost::math::owens_t;
|
||||
#ifdef TEST_CPP_DEC_FLOAT
|
||||
#include <boost/multiprecision/cpp_dec_float.hpp>
|
||||
|
||||
template <class R>
|
||||
inline R convert_to(const char* s)
|
||||
{
|
||||
try{
|
||||
return boost::lexical_cast<R>(s);
|
||||
}
|
||||
catch(const boost::bad_lexical_cast&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#undef SC_
|
||||
#define SC_(x) convert_to<T>(BOOST_STRINGIZE(x))
|
||||
#define SC_(x) BOOST_MATH_TEST_VALUE(x)
|
||||
#endif
|
||||
|
||||
#include "owens_t_T7.hpp"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
//#include <boost/multiprecision/mpc.hpp>
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include <boost/test/tools/floating_point_comparison.hpp>
|
||||
#include <boost/math/tools/test_value.hpp>
|
||||
#include <boost/math/concepts/real_concept.hpp>
|
||||
#include <boost/math/special_functions/bessel.hpp>
|
||||
#include <boost/math/quadrature/trapezoidal.hpp>
|
||||
@@ -52,8 +53,8 @@ void test_complex_bessel()
|
||||
// N[BesselJ[2, 2 + 3 I], 143]
|
||||
// 1.257674591970511077630764085052638490387449039392695959943027966195657681586539389134094087028482099931927725892... +
|
||||
// 2.318771368505683055818032722011594415038779144567369903204833213112457210243098545874099591376455981793627257060... i
|
||||
Real Jnzx = boost::lexical_cast<Real>("1.257674591970511077630764085052638490387449039392695959943027966195657681586539389134094087028482099931927725892");
|
||||
Real Jnzy = boost::lexical_cast<Real>("2.318771368505683055818032722011594415038779144567369903204833213112457210243098545874099591376455981793627257060");
|
||||
Real Jnzx = BOOST_MATH_TEST_VALUE(Real, 1.257674591970511077630764085052638490387449039392695959943027966195657681586539389134094087028482099931927725892);
|
||||
Real Jnzy = BOOST_MATH_TEST_VALUE(Real, 2.318771368505683055818032722011594415038779144567369903204833213112457210243098545874099591376455981793627257060);
|
||||
Real tol = 10*std::numeric_limits<Real>::epsilon();
|
||||
BOOST_CHECK_CLOSE_FRACTION(Jnz.real(), Jnzx, tol);
|
||||
BOOST_CHECK_CLOSE_FRACTION(Jnz.imag(), Jnzy, tol);
|
||||
@@ -81,8 +82,8 @@ void test_I0_complex()
|
||||
// N[BesselI[0, 2 + 3 I], 143]
|
||||
// -1.24923487960742219637619681391438589436703710701063561548156438052154090067526565701278826317992172207565649925713468090525951417141982808439560899101
|
||||
// 0.947983792057734776114060623981442199525094227418764823692296622398838765371662384207319492908490909109393495109183270208372778907692930675595924819922 i
|
||||
Real I0zx = boost::lexical_cast<Real>("-1.24923487960742219637619681391438589436703710701063561548156438052154090067526565701278826317992172207565649925713468090525951417141982808439560899101");
|
||||
Real I0zy = boost::lexical_cast<Real>("0.947983792057734776114060623981442199525094227418764823692296622398838765371662384207319492908490909109393495109183270208372778907692930675595924819922");
|
||||
Real I0zx = BOOST_MATH_TEST_VALUE(Real, -1.24923487960742219637619681391438589436703710701063561548156438052154090067526565701278826317992172207565649925713468090525951417141982808439560899101);
|
||||
Real I0zy = BOOST_MATH_TEST_VALUE(Real, 0.947983792057734776114060623981442199525094227418764823692296622398838765371662384207319492908490909109393495109183270208372778907692930675595924819922);
|
||||
Real tol = 10*std::numeric_limits<Real>::epsilon();
|
||||
BOOST_CHECK_CLOSE_FRACTION(I0z.real(), I0zx, tol);
|
||||
BOOST_CHECK_CLOSE_FRACTION(I0z.imag(), I0zy, tol);
|
||||
@@ -114,8 +115,8 @@ void test_erfc()
|
||||
// N[Erfc[2-i], 150]
|
||||
//-0.00360634272565175091291182820541914235532928536595056623793472801084629874817202107825472707423984408881473019087931573313969503235634965264302640170177
|
||||
// - 0.0112590060288150250764009156316482248536651598819882163212627394923365188251633729432967232423246312345152595958230197778555210858871376231770868078020 i
|
||||
Real erfczx = boost::lexical_cast<Real>("-0.00360634272565175091291182820541914235532928536595056623793472801084629874817202107825472707423984408881473019087931573313969503235634965264302640170177");
|
||||
Real erfczy = boost::lexical_cast<Real>("-0.0112590060288150250764009156316482248536651598819882163212627394923365188251633729432967232423246312345152595958230197778555210858871376231770868078020");
|
||||
Real erfczx = BOOST_MATH_TEST_VALUE(Real, -0.00360634272565175091291182820541914235532928536595056623793472801084629874817202107825472707423984408881473019087931573313969503235634965264302640170177);
|
||||
Real erfczy = BOOST_MATH_TEST_VALUE(Real, -0.0112590060288150250764009156316482248536651598819882163212627394923365188251633729432967232423246312345152595958230197778555210858871376231770868078020);
|
||||
Real tol = 5000*std::numeric_limits<Real>::epsilon();
|
||||
BOOST_CHECK_CLOSE_FRACTION(erfcz.real(), erfczx, tol);
|
||||
BOOST_CHECK_CLOSE_FRACTION(erfcz.imag(), erfczy, tol);
|
||||
@@ -167,7 +168,7 @@ void test_bump_function()
|
||||
Real tol = boost::math::tools::epsilon<Real>();
|
||||
Real Q = trapezoidal(f, (Real) -1, (Real) 1, tol);
|
||||
// 2*NIntegrate[Exp[-(1/(1 - x^2))], {x, 0, 1}, WorkingPrecision -> 210]
|
||||
Real Q_exp = boost::lexical_cast<Real>("0.44399381616807943782304892117055266376120178904569749730748455394704");
|
||||
Real Q_exp = BOOST_MATH_TEST_VALUE(Real, 0.44399381616807943782304892117055266376120178904569749730748455394704);
|
||||
BOOST_CHECK_CLOSE_FRACTION(Q, Q_exp, 30*tol);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user