Skip to content
Merged
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
20 changes: 20 additions & 0 deletions include/boost/decimal/cstdio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ enum class decimal_type : unsigned
decimal128_t = 1 << 2
};

// Internal use only
#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wpadded"
#endif

struct parameters
{
int precision;
Expand All @@ -51,6 +57,10 @@ struct parameters
bool upper_case;
};

#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif

inline auto parse_format(const char* format) -> parameters
{
// If the format is unspecified or incorrect, we will use this as the default values
Expand Down Expand Up @@ -154,6 +164,12 @@ inline void make_uppercase(char* first, const char* last) noexcept
}
}

// Cast of return value avoids warning when sizeof(std::ptrdiff_t) > sizeof(int) e.g. when not in 32-bit
#if defined(__GNUC__) && defined(__i386__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wuseless-cast"
#endif

template <typename... T>
inline auto snprintf_impl(char* buffer, const std::size_t buf_size, const char* format, const T... values) noexcept
#ifndef BOOST_DECIMAL_HAS_CONCEPTS
Expand Down Expand Up @@ -240,6 +256,10 @@ inline auto snprintf_impl(char* buffer, const std::size_t buf_size, const char*
return static_cast<int>(buffer - buffer_begin);
}

#if defined(__GNUC__) && defined(__i386__)
# pragma GCC diagnostic pop
#endif

} // namespace detail

template <typename... T>
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/decimal128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ constexpr auto d128_mod_impl(const decimal128_t& lhs, const decimal128_t& rhs, c
constexpr decimal128_t zero {0, 0};

auto q_trunc {q > zero ? floor(q) : ceil(q)};
r = lhs - (decimal128_t(q_trunc) * rhs);
r = lhs - (q_trunc * rhs);
}

constexpr auto operator+(const decimal128_t& lhs, const decimal128_t& rhs) noexcept -> decimal128_t
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/decimal32_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ constexpr auto mod_impl(const decimal32_t lhs, const decimal32_t rhs, const deci

// https://en.cppreference.com/w/cpp/numeric/math/fmod
auto q_trunc {q > zero ? floor(q) : ceil(q)};
r = lhs - (decimal32_t(q_trunc) * rhs);
r = lhs - (q_trunc * rhs);
}

constexpr auto operator/(const decimal32_t lhs, const decimal32_t rhs) noexcept -> decimal32_t
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/decimal64_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ constexpr auto d64_mod_impl(const decimal64_t lhs, const decimal64_t rhs, const

// https://en.cppreference.com/w/cpp/numeric/math/fmod
auto q_trunc {q > zero ? floor(q) : ceil(q)};
r = lhs - (decimal64_t(q_trunc) * rhs);
r = lhs - (q_trunc * rhs);
}

constexpr auto operator+(const decimal64_t lhs, const decimal64_t rhs) noexcept -> decimal64_t
Expand Down
13 changes: 7 additions & 6 deletions include/boost/decimal/decimal_fast128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ constexpr auto write_payload(typename TargetDecimalType::significand_type payloa
# pragma warning(disable : 4324) // Structure was padded due to alignment specifier
#endif

BOOST_DECIMAL_EXPORT class decimal_fast128_t final
BOOST_DECIMAL_EXPORT class alignas(16) decimal_fast128_t final
{
public:
using significand_type = int128::uint128_t;
Expand All @@ -99,6 +99,7 @@ BOOST_DECIMAL_EXPORT class decimal_fast128_t final
significand_type significand_ {};
exponent_type exponent_ {};
bool sign_ {};
char pad_[11] {};

constexpr auto isneg() const noexcept -> bool
{
Expand Down Expand Up @@ -1035,7 +1036,7 @@ constexpr auto operator+(const decimal_fast128_t& lhs, const decimal_fast128_t&
lhs.significand_, lhs.biased_exponent(), lhs.sign_,
rhs.significand_, rhs.biased_exponent(), rhs.sign_,
(abs(lhs) > abs(rhs)));
};
}

template <typename Integer>
constexpr auto operator+(const decimal_fast128_t& lhs, const Integer rhs) noexcept
Expand Down Expand Up @@ -1304,8 +1305,8 @@ constexpr auto d128f_mod_impl(const decimal_fast128_t& lhs, const decimal_fast12
constexpr decimal_fast128_t zero {0, 0};

auto q_trunc {q > zero ? floor(q) : ceil(q)};
r = lhs - (decimal_fast128_t(q_trunc) * rhs);
};
r = lhs - (q_trunc * rhs);
}

constexpr auto operator/(const decimal_fast128_t& lhs, const decimal_fast128_t& rhs) noexcept -> decimal_fast128_t
{
Expand All @@ -1314,7 +1315,7 @@ constexpr auto operator/(const decimal_fast128_t& lhs, const decimal_fast128_t&
d128f_div_impl(lhs, rhs, q, r);

return q;
};
}

template <typename Integer>
constexpr auto operator/(const decimal_fast128_t& lhs, const Integer rhs) noexcept
Expand Down Expand Up @@ -1405,7 +1406,7 @@ constexpr auto operator%(const decimal_fast128_t& lhs, const decimal_fast128_t&
}

return r;
};
}

constexpr auto decimal_fast128_t::operator+=(const decimal_fast128_t& rhs) noexcept -> decimal_fast128_t&
{
Expand Down
14 changes: 12 additions & 2 deletions include/boost/decimal/decimal_fast32_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ constexpr auto write_payload(typename TargetDecimalType::significand_type payloa

} // namespace detail

BOOST_DECIMAL_EXPORT class decimal_fast32_t final
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4324) // Structure was padded due to alignment specifier
#endif

BOOST_DECIMAL_EXPORT class alignas(4) decimal_fast32_t final
{
public:
using significand_type = std::uint32_t;
Expand All @@ -93,6 +98,7 @@ BOOST_DECIMAL_EXPORT class decimal_fast32_t final
significand_type significand_ {};
exponent_type exponent_ {};
bool sign_ {};
char pad_[2] {};

constexpr auto isneg() const noexcept -> bool
{
Expand Down Expand Up @@ -495,6 +501,10 @@ BOOST_DECIMAL_EXPORT class decimal_fast32_t final
friend constexpr auto quantized32f(decimal_fast32_t lhs, decimal_fast32_t rhs) noexcept -> decimal_fast32_t;
};

#ifdef _MSC_VER
# pragma warning(pop)
#endif

template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool>>
constexpr decimal_fast32_t::decimal_fast32_t(T1 coeff, T2 exp, const detail::construction_sign_wrapper resultant_sign) noexcept
{
Expand Down Expand Up @@ -1259,7 +1269,7 @@ constexpr auto mod_impl(const decimal_fast32_t lhs, const decimal_fast32_t rhs,

// https://en.cppreference.com/w/cpp/numeric/math/fmod
auto q_trunc {q > zero ? floor(q) : ceil(q)};
r = lhs - (decimal_fast32_t(q_trunc) * rhs);
r = lhs - (q_trunc * rhs);
}

constexpr auto operator/(const decimal_fast32_t lhs, const decimal_fast32_t rhs) noexcept -> decimal_fast32_t
Expand Down
14 changes: 12 additions & 2 deletions include/boost/decimal/decimal_fast64_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ constexpr auto write_payload(typename TargetDecimalType::significand_type payloa

} // namespace detail

BOOST_DECIMAL_EXPORT class decimal_fast64_t final
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4324) // Structure was padded due to alignment specifier
#endif

BOOST_DECIMAL_EXPORT class alignas(8) decimal_fast64_t final
{
public:
using significand_type = std::uint64_t;
Expand All @@ -94,6 +99,7 @@ BOOST_DECIMAL_EXPORT class decimal_fast64_t final
significand_type significand_ {};
exponent_type exponent_ {};
bool sign_ {};
char pad_[5] {};

constexpr auto isneg() const noexcept -> bool
{
Expand Down Expand Up @@ -496,6 +502,10 @@ BOOST_DECIMAL_EXPORT class decimal_fast64_t final
friend constexpr auto quantexpd64f(decimal_fast64_t x) noexcept -> int;
};

#ifdef _MSC_VER
# pragma warning(pop)
#endif

#ifdef BOOST_DECIMAL_HAS_CONCEPTS
template <BOOST_DECIMAL_UNSIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
#else
Expand Down Expand Up @@ -1402,7 +1412,7 @@ constexpr auto d64_fast_mod_impl(const decimal_fast64_t lhs, const decimal_fast6

// https://en.cppreference.com/w/cpp/numeric/math/fmod
auto q_trunc {q > zero ? floor(q) : ceil(q)};
r = lhs - (decimal_fast64_t(q_trunc) * rhs);
r = lhs - (q_trunc * rhs);
}

constexpr auto operator/(const decimal_fast64_t& lhs, const decimal_fast64_t& rhs) noexcept -> decimal_fast64_t
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/atan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ constexpr auto atan_impl(const T x) noexcept

if(!is_smallish)
{
constexpr T my_pi_over_six { numbers::pi_v<T> / static_cast<int>(INT8_C(6)) };
constexpr T my_pi_over_six { numbers::pi_v<T> / 6 };

result += my_pi_over_six;
}
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/cos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ constexpr auto cos_impl(const T x) noexcept
const T two_x = x * 2;

const auto k = static_cast<unsigned>(two_x / numbers::pi_v<T>);
const auto n = static_cast<unsigned>(k % static_cast<unsigned>(UINT8_C(4)));
const auto n = k % static_cast<unsigned>(UINT8_C(4));

const T two_r { two_x - (numbers::pi_v<T> * k) };

Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ constexpr auto exp_impl(T x) noexcept
{
if (nf2 < 64)
{
result *= T { static_cast<std::uint64_t>(UINT64_C(1) << static_cast<unsigned>(nf2)), 0 };
result *= T { UINT64_C(1) << static_cast<unsigned>(nf2), 0 };
}
else
{
Expand Down
10 changes: 1 addition & 9 deletions include/boost/decimal/detail/cmath/frexp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,7 @@ constexpr auto frexp_impl(const T v, int* expon) noexcept

if(b_neg) { result_frexp = -result_frexp; }

auto t =
static_cast<int>
(
static_cast<std::int32_t>
(
static_cast<std::int32_t>(ilogb(result_frexp) - detail::bias) * INT32_C(1000)
)
/ INT32_C(301)
);
auto t = static_cast<std::int32_t>(ilogb(result_frexp) - detail::bias) * INT32_C(1000) / 301;

result_frexp *= detail::pow_2_impl<T>(-t);

Expand Down
6 changes: 3 additions & 3 deletions include/boost/decimal/detail/cmath/ilogb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ constexpr auto ilogb(const T d) noexcept

if (fpc == FP_ZERO)
{
result = static_cast<int>(FP_ILOGB0);
result = FP_ILOGB0;
}
#ifndef BOOST_DECIMAL_FAST_MATH
else if (fpc == FP_INFINITE)
{
result = static_cast<int>(INT_MAX);
result = INT_MAX;
}
else if (fpc == FP_NAN)
{
result = static_cast<int>(FP_ILOGBNAN);
result = FP_ILOGBNAN;
}
#endif
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,37 +682,37 @@ constexpr auto assoc_legendre_p0_lookup(unsigned n) -> T;
template <>
constexpr auto assoc_legendre_p0_lookup<decimal32_t>(unsigned n) -> decimal32_t
{
return assoc_legendre_detail::assoc_legendre_lookup_table::d32_values[static_cast<std::size_t>(n)];
return assoc_legendre_detail::assoc_legendre_lookup_table::d32_values[n];
}

template <>
constexpr auto assoc_legendre_p0_lookup<decimal_fast32_t>(unsigned n) -> decimal_fast32_t
{
return assoc_legendre_detail::assoc_legendre_lookup_table::d32_fast_values[static_cast<std::size_t>(n)];
return assoc_legendre_detail::assoc_legendre_lookup_table::d32_fast_values[n];
}

template <>
constexpr auto assoc_legendre_p0_lookup<decimal64_t>(unsigned n) -> decimal64_t
{
return assoc_legendre_detail::assoc_legendre_lookup_table::d64_values[static_cast<std::size_t>(n)];
return assoc_legendre_detail::assoc_legendre_lookup_table::d64_values[n];
}

template <>
constexpr auto assoc_legendre_p0_lookup<decimal_fast64_t>(unsigned n) -> decimal_fast64_t
{
return assoc_legendre_detail::assoc_legendre_lookup_table::d64_fast_values[static_cast<std::size_t>(n)];
return assoc_legendre_detail::assoc_legendre_lookup_table::d64_fast_values[n];
}

template <>
constexpr auto assoc_legendre_p0_lookup<decimal128_t>(unsigned n) -> decimal128_t
{
return assoc_legendre_detail::assoc_legendre_lookup_table::d128_values[static_cast<std::size_t>(n)];
return assoc_legendre_detail::assoc_legendre_lookup_table::d128_values[n];
}

template <>
constexpr auto assoc_legendre_p0_lookup<decimal_fast128_t>(unsigned n) -> decimal_fast128_t
{
return assoc_legendre_detail::assoc_legendre_lookup_table::d128_fast_values[static_cast<std::size_t>(n)];
return assoc_legendre_detail::assoc_legendre_lookup_table::d128_fast_values[n];
}

} //namespace detail
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 @@ -135,7 +135,7 @@ constexpr auto agm(T phi,
}
}

p2 = static_cast<std::uint32_t>(p2 << 1U);
p2 = p2 << 1U;

if(fabs(cn_term) < break_check)
{
Expand Down
6 changes: 3 additions & 3 deletions include/boost/decimal/detail/cmath/impl/pow_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ constexpr auto pow_2_impl(int e2) noexcept -> std::enable_if_t<detail::is_decima
{
if(e2 < 64)
{
result = T { static_cast<std::uint64_t>(UINT64_C(1) << e2), 0 };
result = T { UINT64_C(1) << e2, 0 };
}
else
{
Expand All @@ -97,11 +97,11 @@ constexpr auto pow_2_impl(int e2) noexcept -> std::enable_if_t<detail::is_decima
}
else if(e2 < 0)
{
const auto e2_neg = static_cast<unsigned>(static_cast<unsigned>(~e2) + 1U);
const auto e2_neg = static_cast<unsigned>(~e2) + 1U;

if(e2 > -64)
{
const T local_p2 { static_cast<std::uint64_t>(UINT64_C(1) << e2_neg), 0 };
const T local_p2 { UINT64_C(1) << e2_neg, 0 };

result = one / local_p2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ constexpr auto riemann_zeta_decimal_order(T x) noexcept
: 33
};

return static_cast<int>(n + order_bias);
return n + order_bias;
}

template <typename T>
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 @@ -114,7 +114,7 @@ constexpr auto pow(const T b, const IntegralType p) noexcept
// Here, a pure power-of-10 argument (b) gets a pure integral result.
const int log10_val { exp10val + static_cast<int>(zeros_removal.number_of_removed_zeros) };

result = T { 1, static_cast<int>(log10_val * static_cast<int>(p)) };
result = T { 1, log10_val * static_cast<int>(p) };
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions include/boost/decimal/detail/cmath/sin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ constexpr auto sin_impl(const T x) noexcept
}
else
{
if(x > static_cast<int>(INT8_C(0)))
if(x > 0)
{
// Perform argument reduction and subsequent scaling of the result.

Expand All @@ -65,7 +65,7 @@ constexpr auto sin_impl(const T x) noexcept
const T two_x = x * 2;

const auto k = static_cast<unsigned>(two_x / numbers::pi_v<T>);
const auto n = static_cast<unsigned>(k % static_cast<unsigned>(UINT8_C(4)));
const auto n = k % static_cast<unsigned>(4);

const T two_r { two_x - (numbers::pi_v<T> * k) };

Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/tan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ constexpr auto tan_impl(const T x) noexcept
const T two_x = x * 2;

const auto k = static_cast<unsigned>(two_x / numbers::pi_v<T>);
const auto n = static_cast<unsigned>(k % static_cast<unsigned>(UINT8_C(4)));
const auto n = k % static_cast<unsigned>(UINT8_C(4));

const T two_r { two_x - (numbers::pi_v<T> * k) };

Expand Down
Loading
Loading