Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/boost/decimal/cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef BOOST_DECIMAL_CMATH_HPP
#define BOOST_DECIMAL_CMATH_HPP

#include <boost/decimal/detail/fwd_log.hpp>
#include <boost/decimal/detail/promotion.hpp>
#include <boost/decimal/decimal32_t.hpp>
#include <boost/decimal/decimal64_t.hpp>
Expand Down
6 changes: 3 additions & 3 deletions include/boost/decimal/detail/cmath/acosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ constexpr auto acosh_impl(const T x) noexcept
{
// http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/06/01/0001/
// approximation by laurent series in 1/x at 0+ order from -1 to 0
result = log(x) + numbers::ln2_v<T>;
result = ::boost::decimal::log(x) + numbers::ln2_v<T>;
}
else if (x < T { 15, -1 })
{
Expand All @@ -85,12 +85,12 @@ constexpr auto acosh_impl(const T x) noexcept

const auto two_y = y + y;

result = log1p(y + sqrt((y * y) + two_y));
result = ::boost::decimal::log1p(y + sqrt((y * y) + two_y));
}
else
{
// http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/
return(log(x + sqrt((x * x) - one)));
return(::boost::decimal::log(x + sqrt((x * x) - one)));
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions include/boost/decimal/detail/cmath/asinh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ constexpr auto asinh_impl(const T x) noexcept
{
// http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/06/01/0001/
// approximation by laurent series in 1/x at 0+ order from -1 to 1
result = numbers::ln2_v<T> + log(x) + one / (T { 4, 0 } * xsq);
result = numbers::ln2_v<T> + ::boost::decimal::log(x) + one / (T { 4, 0 } * xsq);
}
else if(x >= T { 5 , -1 })
{
// http://functions.wolfram.com/ElementaryFunctions/ArcSinh/02/
result = log(x + sqrt(xsq + one));
result = ::boost::decimal::log(x + sqrt(xsq + one));
}
else if (x >= fourth_root_epsilon)
{
// As below, but rearranged to preserve digits:
result = log1p(x + (sqrt(one + xsq) - one));
result = ::boost::decimal::log1p(x + (sqrt(one + xsq) - one));
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions include/boost/decimal/detail/cmath/atanh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ constexpr auto atanh_impl(const T x) noexcept

if(xx < half)
{
result = (log1p(xx) - log1p(-xx)) / 2;
result = (::boost::decimal::log1p(xx) - ::boost::decimal::log1p(-xx)) / 2;
}
else
{
result = (log((one + xx) / (one - xx)) / 2);
result = (::boost::decimal::log((one + xx) / (one - xx)) / 2);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/impl/ellint_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ constexpr auto agm(T phi,

const T sp { sin(phi) };

Fpm = phi_is_pi_half ? std::numeric_limits<T>::quiet_NaN() : log((one + sp) / (one - sp)) / 2;
Fpm = phi_is_pi_half ? std::numeric_limits<T>::quiet_NaN() : ::boost::decimal::log((one + sp) / (one - sp)) / 2;

if(has_e)
{
Expand Down
8 changes: 4 additions & 4 deletions include/boost/decimal/detail/cmath/lgamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ constexpr auto lgamma_impl(const T x) noexcept

const auto phase = sin(numbers::pi_v<T> * za);

result = log(numbers::pi_v<T>) - log(abs(phase)) - lgamma(za);
result = ::boost::decimal::log(numbers::pi_v<T>) - ::boost::decimal::log(abs(phase)) - lgamma(za);
}
else
{
Expand All @@ -97,11 +97,11 @@ constexpr auto lgamma_impl(const T x) noexcept
// Perform the Taylor series expansion.

result = (x * fma(detail::lgamma_taylor_series_expansion(x), x, -numbers::egamma_v<T>))
- log(x);
- ::boost::decimal::log(x);
}
else if (x < T { asymp_cutoff })
{
result = log(tgamma(x));
result = ::boost::decimal::log(tgamma(x));
}
else
{
Expand All @@ -111,7 +111,7 @@ constexpr auto lgamma_impl(const T x) noexcept

constexpr T half { 5, -1 };

result = (((x - half) * (log(x)) - x)) + log(detail::tgamma_series_expansion_asymp(one / x));
result = (((x - half) * (::boost::decimal::log(x)) - x)) + ::boost::decimal::log(detail::tgamma_series_expansion_asymp(one / x));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/boost/decimal/detail/cmath/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ constexpr auto log_impl(const T x) noexcept
else if (x < one)
{
// Handle reflection.
result = -log(one / x);
result = -::boost::decimal::log(one / x);
}
else if(x > one)
{
// Use the implementation of log10 in order to compute the natural
// Use the implementation of ::boost::decimal::log10 in order to compute the natural
// logarithm. The base of the boost::decimal library is, in fact,
// base-10. And so, somewhat uncommonly, the fastest and most accurate
// logarithm in this system is log10 in base-10.
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/log10.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ constexpr auto log10_impl(const T x) noexcept
if (x < one)
{
// Handle reflection.
result = -log10(one / x);
result = -::boost::decimal::log10(one / x);
}
else if(x > one)
{
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/log1p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ constexpr auto log1p_impl(const T x) noexcept
{
if (x > T { 5, -1 })
{
result = log(x + one);
result = ::boost::decimal::log(x + one);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/log2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ template <typename T>
constexpr auto log2_impl(const T x) noexcept
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
{
return log(x) / numbers::ln2_v<T>;
return ::boost::decimal::log(x) / numbers::ln2_v<T>;
}

} //namespace detail
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/pow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ constexpr auto pow(const T x, const T a) noexcept
#endif
else
{
const T a_log_x { a * log(x) };
const T a_log_x { a * ::boost::decimal::log(x) };

result = exp(a_log_x);
}
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/riemann_zeta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ constexpr auto riemann_zeta_impl(const T x) noexcept

constexpr std::size_t n_primes = std::tuple_size<prime_table_type>::value;

const T lg10_max_prime { log10(detail::prime_table<T>::primes[n_primes - 1U]) };
const T lg10_max_prime { ::boost::decimal::log10(detail::prime_table<T>::primes[n_primes - 1U]) };

if((x * lg10_max_prime) > std::numeric_limits<T>::digits10)
{
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/tgamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ constexpr auto tgamma_impl(const T x) noexcept
{
// Use large-argument asymptotic expansion.

const T prefix { exp(((x - T { 5, -1 }) * log(x)) - x) };
const T prefix { exp(((x - T { 5, -1 }) * ::boost::decimal::log(x)) - x) };

result = prefix * detail::tgamma_series_expansion_asymp(one / x);
}
Expand Down
39 changes: 39 additions & 0 deletions include/boost/decimal/detail/fwd_log.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2026 Christopher Kormanyos
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_DECIMAL_FWD_LOG_HPP
#define BOOST_DECIMAL_FWD_LOG_HPP

#include <boost/decimal/detail/concepts.hpp>

namespace boost {
namespace decimal {

// Forward declarationf of logarithmic functions.
// See also: https://github.com/boostorg/decimal/issues/1384

BOOST_DECIMAL_EXPORT template <typename T>
constexpr auto ilogb(const T d) noexcept
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_decimal_floating_point_v, T, int);

BOOST_DECIMAL_EXPORT template <typename T>
constexpr auto log(const T x) noexcept
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T);

BOOST_DECIMAL_EXPORT template <typename T>
constexpr auto log1p(const T x) noexcept
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T);

BOOST_DECIMAL_EXPORT template <typename T>
constexpr auto log10(const T x) noexcept
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T);

BOOST_DECIMAL_EXPORT template <typename T>
constexpr auto log2(const T x) noexcept
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T);

} // namespace decimal
} // namespace boost

#endif // BOOST_DECIMAL_FWD_LOG_HPP
5 changes: 3 additions & 2 deletions test/Jamfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2022 Peter Dimov
# Copyright 2023 - 2024 Matt Borland
# Copyright 2023 - 2024 Christopher Kormanyos
# Copyright 2023 - 2026 Matt Borland
# Copyright 2023 - 2026 Christopher Kormanyos
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt

Expand Down Expand Up @@ -93,6 +93,7 @@ run github_issue_1319.cpp ;
run github_issue_1329.cpp ;
run github_issue_1361.cpp ;
run github_issue_1378.cpp ;
run github_issue_1384.cpp ;

run link_1.cpp link_2.cpp link_3.cpp ;
run quick.cpp ;
Expand Down
38 changes: 38 additions & 0 deletions test/github_issue_1384.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

#include <boost/core/lightweight_test.hpp>

// This simulates upstream inclusion of Boost.Log. At the time of
// hash commit e9951622837f63cf0020b22834ad96b01293fd07, this failed.

// This odd-looking test in CI is intended to ensure that such failures
// no longer occur in the future and that the namespace resolution
// remains unequivocal.

namespace boost {
namespace log {

auto do_something() -> void
{
}

} // namespace log
} // namespace boost

#include <boost/decimal/cmath.hpp>

auto main() -> int;

auto main() -> int
{
using local_decimal_type = boost::decimal::decimal64_t;

const local_decimal_type arg_dec { 1.23456 };

const local_decimal_type result1 { acosh(arg_dec) };
const local_decimal_type result2 { lgamma(arg_dec) };

BOOST_TEST(result1 > local_decimal_type { 0.0 });
BOOST_TEST(result2 < local_decimal_type { 0.0 });

return boost::report_errors();
}
Loading