mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
* try to fix precision error on x86 platform step3.
This commit is contained in:
parent
e96afe608e
commit
77ef46838c
@ -60,10 +60,10 @@ from_chars_advanced(UC const *first, UC const *last, T &value,
|
|||||||
*/
|
*/
|
||||||
FASTFLOAT_CONSTEXPR20 inline double
|
FASTFLOAT_CONSTEXPR20 inline double
|
||||||
integer_times_pow10(uint64_t const mantissa,
|
integer_times_pow10(uint64_t const mantissa,
|
||||||
int const decimal_exponent) noexcept;
|
int16_t const decimal_exponent) noexcept;
|
||||||
FASTFLOAT_CONSTEXPR20 inline double
|
FASTFLOAT_CONSTEXPR20 inline double
|
||||||
integer_times_pow10(int64_t const mantissa,
|
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()`
|
* This function is a template overload of `integer_times_pow10()`
|
||||||
@ -74,12 +74,12 @@ template <typename T>
|
|||||||
FASTFLOAT_CONSTEXPR20
|
FASTFLOAT_CONSTEXPR20
|
||||||
typename std::enable_if<is_supported_float_type<T>::value, T>::type
|
typename std::enable_if<is_supported_float_type<T>::value, T>::type
|
||||||
integer_times_pow10(uint64_t const mantissa,
|
integer_times_pow10(uint64_t const mantissa,
|
||||||
int const decimal_exponent) noexcept;
|
int16_t const decimal_exponent) noexcept;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
FASTFLOAT_CONSTEXPR20
|
FASTFLOAT_CONSTEXPR20
|
||||||
typename std::enable_if<is_supported_float_type<T>::value, T>::type
|
typename std::enable_if<is_supported_float_type<T>::value, T>::type
|
||||||
integer_times_pow10(int64_t const mantissa,
|
integer_times_pow10(int64_t const mantissa,
|
||||||
int const decimal_exponent) noexcept;
|
int16_t const decimal_exponent) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* from_chars for integer types.
|
* from_chars for integer types.
|
||||||
|
|||||||
@ -446,7 +446,8 @@ typedef int_fast8_t am_bits_t;
|
|||||||
|
|
||||||
// Power bias is signed for handling a denormal float
|
// Power bias is signed for handling a denormal float
|
||||||
// or an invalid mantissa.
|
// 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.
|
// Bias so we can get the real exponent with an invalid adjusted_mantissa.
|
||||||
constexpr static am_pow_t invalid_am_bias = -0x8000;
|
constexpr static am_pow_t invalid_am_bias = -0x8000;
|
||||||
|
|||||||
@ -388,7 +388,7 @@ template <typename T>
|
|||||||
FASTFLOAT_CONSTEXPR20
|
FASTFLOAT_CONSTEXPR20
|
||||||
typename std::enable_if<is_supported_float_type<T>::value, T>::type
|
typename std::enable_if<is_supported_float_type<T>::value, T>::type
|
||||||
integer_times_pow10(uint64_t const mantissa,
|
integer_times_pow10(uint64_t const mantissa,
|
||||||
int const decimal_exponent) noexcept {
|
int16_t const decimal_exponent) noexcept {
|
||||||
T value;
|
T value;
|
||||||
if (clinger_fast_path_impl(mantissa, decimal_exponent,
|
if (clinger_fast_path_impl(mantissa, decimal_exponent,
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
@ -411,7 +411,7 @@ template <typename T>
|
|||||||
FASTFLOAT_CONSTEXPR20
|
FASTFLOAT_CONSTEXPR20
|
||||||
typename std::enable_if<is_supported_float_type<T>::value, T>::type
|
typename std::enable_if<is_supported_float_type<T>::value, T>::type
|
||||||
integer_times_pow10(int64_t const mantissa,
|
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
|
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
FASTFLOAT_ASSUME(mantissa > 0);
|
FASTFLOAT_ASSUME(mantissa > 0);
|
||||||
const am_mant_t m = static_cast<am_mant_t>(mantissa);
|
const am_mant_t m = static_cast<am_mant_t>(mantissa);
|
||||||
@ -440,13 +440,13 @@ FASTFLOAT_CONSTEXPR20
|
|||||||
|
|
||||||
FASTFLOAT_CONSTEXPR20 inline double
|
FASTFLOAT_CONSTEXPR20 inline double
|
||||||
integer_times_pow10(uint64_t const mantissa,
|
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);
|
return integer_times_pow10<double>(mantissa, decimal_exponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
FASTFLOAT_CONSTEXPR20 inline double
|
FASTFLOAT_CONSTEXPR20 inline double
|
||||||
integer_times_pow10(int64_t const mantissa,
|
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);
|
return integer_times_pow10<double>(mantissa, decimal_exponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ FASTFLOAT_CONSTEXPR20
|
|||||||
std::is_integral<Int>::value &&
|
std::is_integral<Int>::value &&
|
||||||
!std::is_signed<Int>::value,
|
!std::is_signed<Int>::value,
|
||||||
T>::type
|
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),
|
return integer_times_pow10<T>(static_cast<uint64_t>(mantissa),
|
||||||
decimal_exponent);
|
decimal_exponent);
|
||||||
}
|
}
|
||||||
@ -469,7 +469,7 @@ FASTFLOAT_CONSTEXPR20
|
|||||||
std::is_integral<Int>::value &&
|
std::is_integral<Int>::value &&
|
||||||
std::is_signed<Int>::value,
|
std::is_signed<Int>::value,
|
||||||
T>::type
|
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),
|
return integer_times_pow10<T>(static_cast<int64_t>(mantissa),
|
||||||
decimal_exponent);
|
decimal_exponent);
|
||||||
}
|
}
|
||||||
@ -477,14 +477,14 @@ FASTFLOAT_CONSTEXPR20
|
|||||||
template <typename Int>
|
template <typename Int>
|
||||||
FASTFLOAT_CONSTEXPR20 typename std::enable_if<
|
FASTFLOAT_CONSTEXPR20 typename std::enable_if<
|
||||||
std::is_integral<Int>::value && !std::is_signed<Int>::value, double>::type
|
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);
|
return integer_times_pow10(static_cast<uint64_t>(mantissa), decimal_exponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Int>
|
template <typename Int>
|
||||||
FASTFLOAT_CONSTEXPR20 typename std::enable_if<
|
FASTFLOAT_CONSTEXPR20 typename std::enable_if<
|
||||||
std::is_integral<Int>::value && std::is_signed<Int>::value, double>::type
|
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);
|
return integer_times_pow10(static_cast<int64_t>(mantissa), decimal_exponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2127,7 +2127,7 @@ TEST_CASE("bfloat16.general") {
|
|||||||
|
|
||||||
template <typename Int, typename T, typename U>
|
template <typename Int, typename T, typename U>
|
||||||
void verify_integer_times_pow10_result(Int const mantissa,
|
void verify_integer_times_pow10_result(Int const mantissa,
|
||||||
int const decimal_exponent,
|
int16_t const decimal_exponent,
|
||||||
T const actual, U const expected) {
|
T const actual, U const expected) {
|
||||||
static_assert(std::is_same<T, U>::value,
|
static_assert(std::is_same<T, U>::value,
|
||||||
"expected and actual types must match");
|
"expected and actual types must match");
|
||||||
@ -2145,8 +2145,8 @@ void verify_integer_times_pow10_result(Int const mantissa,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename Int>
|
template <typename T, typename Int>
|
||||||
T calculate_integer_times_pow10_expected_result(Int const mantissa,
|
T calculate_integer_times_pow10_expected_result(
|
||||||
int const decimal_exponent) {
|
Int const mantissa, int16_t const decimal_exponent) {
|
||||||
std::string constructed_string =
|
std::string constructed_string =
|
||||||
std::to_string(mantissa) + "e" + std::to_string(decimal_exponent);
|
std::to_string(mantissa) + "e" + std::to_string(decimal_exponent);
|
||||||
T expected_result;
|
T expected_result;
|
||||||
@ -2160,7 +2160,7 @@ T calculate_integer_times_pow10_expected_result(Int const mantissa,
|
|||||||
|
|
||||||
template <typename Int>
|
template <typename Int>
|
||||||
void verify_integer_times_pow10_dflt(Int const mantissa,
|
void verify_integer_times_pow10_dflt(Int const mantissa,
|
||||||
int const decimal_exponent,
|
int16_t const decimal_exponent,
|
||||||
double const expected) {
|
double const expected) {
|
||||||
static_assert(std::is_integral<Int>::value);
|
static_assert(std::is_integral<Int>::value);
|
||||||
|
|
||||||
@ -2174,7 +2174,7 @@ void verify_integer_times_pow10_dflt(Int const mantissa,
|
|||||||
|
|
||||||
template <typename Int>
|
template <typename Int>
|
||||||
void verify_integer_times_pow10_dflt(Int const mantissa,
|
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);
|
static_assert(std::is_integral<Int>::value);
|
||||||
|
|
||||||
const auto expected_result =
|
const auto expected_result =
|
||||||
@ -2185,7 +2185,8 @@ void verify_integer_times_pow10_dflt(Int const mantissa,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename Int>
|
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) {
|
T const expected) {
|
||||||
static_assert(std::is_floating_point<T>::value);
|
static_assert(std::is_floating_point<T>::value);
|
||||||
static_assert(std::is_integral<Int>::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>
|
template <typename T, typename Int>
|
||||||
void verify_integer_times_pow10(Int const mantissa,
|
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_floating_point<T>::value);
|
||||||
static_assert(std::is_integral<Int>::value);
|
static_assert(std::is_integral<Int>::value);
|
||||||
|
|
||||||
@ -2213,7 +2214,7 @@ void verify_integer_times_pow10(Int const mantissa,
|
|||||||
namespace all_supported_types {
|
namespace all_supported_types {
|
||||||
template <typename Int>
|
template <typename Int>
|
||||||
void verify_integer_times_pow10(Int const mantissa,
|
void verify_integer_times_pow10(Int const mantissa,
|
||||||
int const decimal_exponent) {
|
int16_t const decimal_exponent) {
|
||||||
static_assert(std::is_integral<Int>::value);
|
static_assert(std::is_integral<Int>::value);
|
||||||
|
|
||||||
// verify the "default" overload
|
// verify the "default" overload
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user