* try to fix precision error on x86 platform step3.

This commit is contained in:
IRainman 2025-11-08 19:40:24 +03:00
parent e96afe608e
commit 77ef46838c
4 changed files with 23 additions and 21 deletions

View File

@ -60,10 +60,10 @@ from_chars_advanced(UC const *first, UC const *last, T &value,
*/
FASTFLOAT_CONSTEXPR20 inline double
integer_times_pow10(uint64_t const mantissa,
int const decimal_exponent) noexcept;
int16_t const decimal_exponent) noexcept;
FASTFLOAT_CONSTEXPR20 inline double
integer_times_pow10(int64_t const mantissa,
int const decimal_exponent) noexcept;
int16_t const decimal_exponent) noexcept;
/**
* This function is a template overload of `integer_times_pow10()`
@ -74,12 +74,12 @@ template <typename T>
FASTFLOAT_CONSTEXPR20
typename std::enable_if<is_supported_float_type<T>::value, T>::type
integer_times_pow10(uint64_t const mantissa,
int const decimal_exponent) noexcept;
int16_t const decimal_exponent) noexcept;
template <typename T>
FASTFLOAT_CONSTEXPR20
typename std::enable_if<is_supported_float_type<T>::value, T>::type
integer_times_pow10(int64_t const mantissa,
int const decimal_exponent) noexcept;
int16_t const decimal_exponent) noexcept;
/**
* from_chars for integer types.

View File

@ -446,7 +446,8 @@ typedef int_fast8_t am_bits_t;
// Power bias is signed for handling a denormal float
// or an invalid mantissa.
typedef int16_t am_pow_t; // can't be int_fast16_t because invalid_am_bias hacks. Needs rewriting this.
typedef int16_t am_pow_t; // can't be int_fast16_t because invalid_am_bias
// hacks. Needs rewriting this.
// Bias so we can get the real exponent with an invalid adjusted_mantissa.
constexpr static am_pow_t invalid_am_bias = -0x8000;

View File

@ -388,7 +388,7 @@ template <typename T>
FASTFLOAT_CONSTEXPR20
typename std::enable_if<is_supported_float_type<T>::value, T>::type
integer_times_pow10(uint64_t const mantissa,
int const decimal_exponent) noexcept {
int16_t const decimal_exponent) noexcept {
T value;
if (clinger_fast_path_impl(mantissa, decimal_exponent,
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
@ -411,7 +411,7 @@ template <typename T>
FASTFLOAT_CONSTEXPR20
typename std::enable_if<is_supported_float_type<T>::value, T>::type
integer_times_pow10(int64_t const mantissa,
int const decimal_exponent) noexcept {
int16_t const decimal_exponent) noexcept {
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
FASTFLOAT_ASSUME(mantissa > 0);
const am_mant_t m = static_cast<am_mant_t>(mantissa);
@ -440,13 +440,13 @@ FASTFLOAT_CONSTEXPR20
FASTFLOAT_CONSTEXPR20 inline double
integer_times_pow10(uint64_t const mantissa,
int const decimal_exponent) noexcept {
int16_t const decimal_exponent) noexcept {
return integer_times_pow10<double>(mantissa, decimal_exponent);
}
FASTFLOAT_CONSTEXPR20 inline double
integer_times_pow10(int64_t const mantissa,
int const decimal_exponent) noexcept {
int16_t const decimal_exponent) noexcept {
return integer_times_pow10<double>(mantissa, decimal_exponent);
}
@ -458,7 +458,7 @@ FASTFLOAT_CONSTEXPR20
std::is_integral<Int>::value &&
!std::is_signed<Int>::value,
T>::type
integer_times_pow10(Int mantissa, int decimal_exponent) noexcept {
integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept {
return integer_times_pow10<T>(static_cast<uint64_t>(mantissa),
decimal_exponent);
}
@ -469,7 +469,7 @@ FASTFLOAT_CONSTEXPR20
std::is_integral<Int>::value &&
std::is_signed<Int>::value,
T>::type
integer_times_pow10(Int mantissa, int decimal_exponent) noexcept {
integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept {
return integer_times_pow10<T>(static_cast<int64_t>(mantissa),
decimal_exponent);
}
@ -477,14 +477,14 @@ FASTFLOAT_CONSTEXPR20
template <typename Int>
FASTFLOAT_CONSTEXPR20 typename std::enable_if<
std::is_integral<Int>::value && !std::is_signed<Int>::value, double>::type
integer_times_pow10(Int mantissa, int decimal_exponent) noexcept {
integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept {
return integer_times_pow10(static_cast<uint64_t>(mantissa), decimal_exponent);
}
template <typename Int>
FASTFLOAT_CONSTEXPR20 typename std::enable_if<
std::is_integral<Int>::value && std::is_signed<Int>::value, double>::type
integer_times_pow10(Int mantissa, int decimal_exponent) noexcept {
integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept {
return integer_times_pow10(static_cast<int64_t>(mantissa), decimal_exponent);
}

View File

@ -2127,7 +2127,7 @@ TEST_CASE("bfloat16.general") {
template <typename Int, typename T, typename U>
void verify_integer_times_pow10_result(Int const mantissa,
int const decimal_exponent,
int16_t const decimal_exponent,
T const actual, U const expected) {
static_assert(std::is_same<T, U>::value,
"expected and actual types must match");
@ -2145,8 +2145,8 @@ void verify_integer_times_pow10_result(Int const mantissa,
}
template <typename T, typename Int>
T calculate_integer_times_pow10_expected_result(Int const mantissa,
int const decimal_exponent) {
T calculate_integer_times_pow10_expected_result(
Int const mantissa, int16_t const decimal_exponent) {
std::string constructed_string =
std::to_string(mantissa) + "e" + std::to_string(decimal_exponent);
T expected_result;
@ -2160,7 +2160,7 @@ T calculate_integer_times_pow10_expected_result(Int const mantissa,
template <typename Int>
void verify_integer_times_pow10_dflt(Int const mantissa,
int const decimal_exponent,
int16_t const decimal_exponent,
double const expected) {
static_assert(std::is_integral<Int>::value);
@ -2174,7 +2174,7 @@ void verify_integer_times_pow10_dflt(Int const mantissa,
template <typename Int>
void verify_integer_times_pow10_dflt(Int const mantissa,
int const decimal_exponent) {
int16_t const decimal_exponent) {
static_assert(std::is_integral<Int>::value);
const auto expected_result =
@ -2185,7 +2185,8 @@ void verify_integer_times_pow10_dflt(Int const mantissa,
}
template <typename T, typename Int>
void verify_integer_times_pow10(Int const mantissa, int const decimal_exponent,
void verify_integer_times_pow10(Int const mantissa,
int16_t const decimal_exponent,
T const expected) {
static_assert(std::is_floating_point<T>::value);
static_assert(std::is_integral<Int>::value);
@ -2200,7 +2201,7 @@ void verify_integer_times_pow10(Int const mantissa, int const decimal_exponent,
template <typename T, typename Int>
void verify_integer_times_pow10(Int const mantissa,
int const decimal_exponent) {
int16_t const decimal_exponent) {
static_assert(std::is_floating_point<T>::value);
static_assert(std::is_integral<Int>::value);
@ -2213,7 +2214,7 @@ void verify_integer_times_pow10(Int const mantissa,
namespace all_supported_types {
template <typename Int>
void verify_integer_times_pow10(Int const mantissa,
int const decimal_exponent) {
int16_t const decimal_exponent) {
static_assert(std::is_integral<Int>::value);
// verify the "default" overload