fix warnings.

This commit is contained in:
IRainman 2025-04-10 18:23:01 +03:00
parent 6cacae0782
commit 68fe735829
2 changed files with 72 additions and 70 deletions

View File

@ -101,7 +101,7 @@ template <uint8_t size> struct stackvec {
FASTFLOAT_CONSTEXPR20 void extend_unchecked(limb_span s) noexcept { FASTFLOAT_CONSTEXPR20 void extend_unchecked(limb_span s) noexcept {
limb *ptr = data + length; limb *ptr = data + length;
std::copy_n(s.ptr, s.len(), ptr); std::copy_n(s.ptr, s.len(), ptr);
set_len(len() + s.len()); set_len(uint8_t(len() + s.len()));
} }
// try to add items to the vector, returning if items were added // try to add items to the vector, returning if items were added
@ -304,7 +304,7 @@ FASTFLOAT_CONSTEXPR20 bool large_add_from(stackvec<size> &x, limb_span y,
// the effective x buffer is from `xstart..x.len()`, so exit early // the effective x buffer is from `xstart..x.len()`, so exit early
// if we can't get that current range. // if we can't get that current range.
if (x.len() < start || y.len() > x.len() - start) { if (x.len() < start || y.len() > x.len() - start) {
FASTFLOAT_TRY(x.try_resize(y.len() + start, 0)); FASTFLOAT_TRY(x.try_resize(uint8_t(y.len() + start), 0));
} }
bool carry = false; bool carry = false;
@ -547,7 +547,7 @@ struct bigint : pow5_tables<> {
limb *first = vec.data; limb *first = vec.data;
limb *last = first + n; limb *last = first + n;
::std::fill(first, last, 0); ::std::fill(first, last, 0);
vec.set_len(n + vec.len()); vec.set_len(uint8_t(n + vec.len()));
return true; return true;
} else { } else {
return true; return true;

View File

@ -451,23 +451,25 @@ template <typename T, typename U = void> struct binary_format_lookup_tables;
template <typename T> struct binary_format : binary_format_lookup_tables<T> { template <typename T> struct binary_format : binary_format_lookup_tables<T> {
using equiv_uint = equiv_uint_t<T>; using equiv_uint = equiv_uint_t<T>;
// TODO add type for bit shift operations and use it.
// TODO add type for exponent operations and use it.
static constexpr int mantissa_explicit_bits(); static constexpr uint8_t mantissa_explicit_bits();
static constexpr int minimum_exponent(); static constexpr int16_t minimum_exponent();
static constexpr int infinite_power(); static constexpr int16_t infinite_power();
static constexpr int sign_index(); static constexpr uint8_t sign_index();
static constexpr int static constexpr int8_t
min_exponent_fast_path(); // used when fegetround() == FE_TONEAREST min_exponent_fast_path(); // used when fegetround() == FE_TONEAREST
static constexpr int max_exponent_fast_path(); static constexpr int8_t max_exponent_fast_path();
static constexpr int max_exponent_round_to_even(); static constexpr int16_t max_exponent_round_to_even();
static constexpr int min_exponent_round_to_even(); static constexpr int16_t min_exponent_round_to_even();
static constexpr uint64_t max_mantissa_fast_path(int64_t power); static constexpr equiv_uint max_mantissa_fast_path(int64_t power);
static constexpr uint64_t static constexpr equiv_uint
max_mantissa_fast_path(); // used when fegetround() == FE_TONEAREST max_mantissa_fast_path(); // used when fegetround() == FE_TONEAREST
static constexpr int largest_power_of_ten(); static constexpr int16_t largest_power_of_ten();
static constexpr int smallest_power_of_ten(); static constexpr int16_t smallest_power_of_ten();
static constexpr T exact_power_of_ten(int64_t power); static constexpr T exact_power_of_ten(int64_t power);
static constexpr size_t max_digits(); static constexpr uint16_t max_digits();
static constexpr equiv_uint exponent_mask(); static constexpr equiv_uint exponent_mask();
static constexpr equiv_uint mantissa_mask(); static constexpr equiv_uint mantissa_mask();
static constexpr equiv_uint hidden_bit_mask(); static constexpr equiv_uint hidden_bit_mask();
@ -531,7 +533,7 @@ template <typename U> struct binary_format_lookup_tables<float, U> {
// Largest integer value v so that (5**index * v) <= 1<<24. // Largest integer value v so that (5**index * v) <= 1<<24.
// 0x1000000 == 1<<24 // 0x1000000 == 1<<24
static constexpr uint64_t max_mantissa[] = { static constexpr uint32_t max_mantissa[] = {
0x1000000, 0x1000000,
0x1000000 / 5, 0x1000000 / 5,
0x1000000 / (5 * 5), 0x1000000 / (5 * 5),
@ -557,7 +559,7 @@ constexpr uint64_t binary_format_lookup_tables<float, U>::max_mantissa[];
#endif #endif
template <> template <>
inline constexpr int binary_format<double>::min_exponent_fast_path() { inline constexpr int8_t binary_format<double>::min_exponent_fast_path() {
#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0) #if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
return 0; return 0;
#else #else
@ -566,7 +568,7 @@ inline constexpr int binary_format<double>::min_exponent_fast_path() {
} }
template <> template <>
inline constexpr int binary_format<float>::min_exponent_fast_path() { inline constexpr int8_t binary_format<float>::min_exponent_fast_path() {
#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0) #if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
return 0; return 0;
#else #else
@ -575,70 +577,70 @@ inline constexpr int binary_format<float>::min_exponent_fast_path() {
} }
template <> template <>
inline constexpr int binary_format<double>::mantissa_explicit_bits() { inline constexpr uint8_t binary_format<double>::mantissa_explicit_bits() {
return 52; return 52;
} }
template <> template <>
inline constexpr int binary_format<float>::mantissa_explicit_bits() { inline constexpr uint8_t binary_format<float>::mantissa_explicit_bits() {
return 23; return 23;
} }
template <> template <>
inline constexpr int binary_format<double>::max_exponent_round_to_even() { inline constexpr int16_t binary_format<double>::max_exponent_round_to_even() {
return 23; return 23;
} }
template <> template <>
inline constexpr int binary_format<float>::max_exponent_round_to_even() { inline constexpr int16_t binary_format<float>::max_exponent_round_to_even() {
return 10; return 10;
} }
template <> template <>
inline constexpr int binary_format<double>::min_exponent_round_to_even() { inline constexpr int16_t binary_format<double>::min_exponent_round_to_even() {
return -4; return -4;
} }
template <> template <>
inline constexpr int binary_format<float>::min_exponent_round_to_even() { inline constexpr int16_t binary_format<float>::min_exponent_round_to_even() {
return -17; return -17;
} }
template <> inline constexpr int binary_format<double>::minimum_exponent() { template <> inline constexpr int16_t binary_format<double>::minimum_exponent() {
return -1023; return -1023;
} }
template <> inline constexpr int binary_format<float>::minimum_exponent() { template <> inline constexpr int16_t binary_format<float>::minimum_exponent() {
return -127; return -127;
} }
template <> inline constexpr int binary_format<double>::infinite_power() { template <> inline constexpr int16_t binary_format<double>::infinite_power() {
return 0x7FF; return 0x7FF;
} }
template <> inline constexpr int binary_format<float>::infinite_power() { template <> inline constexpr int16_t binary_format<float>::infinite_power() {
return 0xFF; return 0xFF;
} }
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
template <> inline constexpr int binary_format<double>::sign_index() { template <> inline constexpr uint8_t binary_format<double>::sign_index() {
return 63; return 63;
} }
template <> inline constexpr int binary_format<float>::sign_index() { template <> inline constexpr uint8_t binary_format<float>::sign_index() {
return 31; return 31;
} }
#endif #endif
template <> template <>
inline constexpr int binary_format<double>::max_exponent_fast_path() { inline constexpr int8_t binary_format<double>::max_exponent_fast_path() {
return 22; return 22;
} }
template <> template <>
inline constexpr int binary_format<float>::max_exponent_fast_path() { inline constexpr int8_t binary_format<float>::max_exponent_fast_path() {
return 10; return 10;
} }
@ -648,8 +650,8 @@ inline constexpr uint64_t binary_format<double>::max_mantissa_fast_path() {
} }
template <> template <>
inline constexpr uint64_t binary_format<float>::max_mantissa_fast_path() { inline constexpr uint32_t binary_format<float>::max_mantissa_fast_path() {
return uint64_t(2) << mantissa_explicit_bits(); return uint32_t(2) << mantissa_explicit_bits();
} }
// credit: Jakub Jelínek // credit: Jakub Jelínek
@ -660,7 +662,7 @@ template <typename U> struct binary_format_lookup_tables<std::float16_t, U> {
// Largest integer value v so that (5**index * v) <= 1<<11. // Largest integer value v so that (5**index * v) <= 1<<11.
// 0x800 == 1<<11 // 0x800 == 1<<11
static constexpr uint64_t max_mantissa[] = {0x800, static constexpr uint16_t max_mantissa[] = {0x800,
0x800 / 5, 0x800 / 5,
0x800 / (5 * 5), 0x800 / (5 * 5),
0x800 / (5 * 5 * 5), 0x800 / (5 * 5 * 5),
@ -675,7 +677,7 @@ constexpr std::float16_t
binary_format_lookup_tables<std::float16_t, U>::powers_of_ten[]; binary_format_lookup_tables<std::float16_t, U>::powers_of_ten[];
template <typename U> template <typename U>
constexpr uint64_t constexpr uint16_t
binary_format_lookup_tables<std::float16_t, U>::max_mantissa[]; binary_format_lookup_tables<std::float16_t, U>::max_mantissa[];
#endif #endif
@ -706,19 +708,19 @@ binary_format<std::float16_t>::hidden_bit_mask() {
} }
template <> template <>
inline constexpr int binary_format<std::float16_t>::max_exponent_fast_path() { inline constexpr int8_t binary_format<std::float16_t>::max_exponent_fast_path() {
return 4; return 4;
} }
template <> template <>
inline constexpr int binary_format<std::float16_t>::mantissa_explicit_bits() { inline constexpr uint8_t binary_format<std::float16_t>::mantissa_explicit_bits() {
return 10; return 10;
} }
template <> template <>
inline constexpr uint64_t inline constexpr int8_t
binary_format<std::float16_t>::max_mantissa_fast_path() { binary_format<std::float16_t>::max_mantissa_fast_path() {
return uint64_t(2) << mantissa_explicit_bits(); return uint16_t(2) << mantissa_explicit_bits();
} }
template <> template <>
@ -732,52 +734,52 @@ binary_format<std::float16_t>::max_mantissa_fast_path(int64_t power) {
} }
template <> template <>
inline constexpr int binary_format<std::float16_t>::min_exponent_fast_path() { inline constexpr int8_t binary_format<std::float16_t>::min_exponent_fast_path() {
return 0; return 0;
} }
template <> template <>
inline constexpr int inline constexpr int16_t
binary_format<std::float16_t>::max_exponent_round_to_even() { binary_format<std::float16_t>::max_exponent_round_to_even() {
return 5; return 5;
} }
template <> template <>
inline constexpr int inline constexpr int16_t
binary_format<std::float16_t>::min_exponent_round_to_even() { binary_format<std::float16_t>::min_exponent_round_to_even() {
return -22; return -22;
} }
template <> template <>
inline constexpr int binary_format<std::float16_t>::minimum_exponent() { inline constexpr int16_t binary_format<std::float16_t>::minimum_exponent() {
return -15; return -15;
} }
template <> template <>
inline constexpr int binary_format<std::float16_t>::infinite_power() { inline constexpr int16_t binary_format<std::float16_t>::infinite_power() {
return 0x1F; return 0x1F;
} }
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
template <> inline constexpr unsigned int binary_format<std::float16_t>::sign_index() { template <> inline constexpr uint8_t binary_format<std::float16_t>::sign_index() {
return 15; return 15;
} }
#endif #endif
template <> template <>
inline constexpr int binary_format<std::float16_t>::largest_power_of_ten() { inline constexpr int16_t binary_format<std::float16_t>::largest_power_of_ten() {
return 4; return 4;
} }
template <> template <>
inline constexpr int binary_format<std::float16_t>::smallest_power_of_ten() { inline constexpr int16_t binary_format<std::float16_t>::smallest_power_of_ten() {
return -27; return -27;
} }
template <> template <>
inline constexpr size_t binary_format<std::float16_t>::max_digits() { inline constexpr uint8_t binary_format<std::float16_t>::max_digits() {
return 22; return 22;
} }
#endif // __STDCPP_FLOAT16_T__ #endif // __STDCPP_FLOAT16_T__
@ -815,7 +817,7 @@ binary_format<std::bfloat16_t>::exact_power_of_ten(int64_t power) {
} }
template <> template <>
inline constexpr int binary_format<std::bfloat16_t>::max_exponent_fast_path() { inline constexpr int8_t binary_format<std::bfloat16_t>::max_exponent_fast_path() {
return 3; return 3;
} }
@ -838,14 +840,14 @@ binary_format<std::bfloat16_t>::hidden_bit_mask() {
} }
template <> template <>
inline constexpr int binary_format<std::bfloat16_t>::mantissa_explicit_bits() { inline constexpr uint8_t binary_format<std::bfloat16_t>::mantissa_explicit_bits() {
return 7; return 7;
} }
template <> template <>
inline constexpr uint64_t inline constexpr binary_format<std::bfloat16_t>::equiv_uint
binary_format<std::bfloat16_t>::max_mantissa_fast_path() { binary_format<std::bfloat16_t>::max_mantissa_fast_path() {
return uint64_t(2) << mantissa_explicit_bits(); return binary_format<std::bfloat16_t>::equiv_uint(2) << mantissa_explicit_bits();
} }
template <> template <>
@ -859,52 +861,52 @@ binary_format<std::bfloat16_t>::max_mantissa_fast_path(int64_t power) {
} }
template <> template <>
inline constexpr int binary_format<std::bfloat16_t>::min_exponent_fast_path() { inline constexpr int8_t binary_format<std::bfloat16_t>::min_exponent_fast_path() {
return 0; return 0;
} }
template <> template <>
inline constexpr int inline constexpr int16_t
binary_format<std::bfloat16_t>::max_exponent_round_to_even() { binary_format<std::bfloat16_t>::max_exponent_round_to_even() {
return 3; return 3;
} }
template <> template <>
inline constexpr int inline constexpr int16_t
binary_format<std::bfloat16_t>::min_exponent_round_to_even() { binary_format<std::bfloat16_t>::min_exponent_round_to_even() {
return -24; return -24;
} }
template <> template <>
inline constexpr int binary_format<std::bfloat16_t>::minimum_exponent() { inline constexpr int16_t binary_format<std::bfloat16_t>::minimum_exponent() {
return -127; return -127;
} }
template <> template <>
inline constexpr int binary_format<std::bfloat16_t>::infinite_power() { inline constexpr int16_t binary_format<std::bfloat16_t>::infinite_power() {
return 0xFF; return 0xFF;
} }
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
template <> inline constexpr int binary_format<std::bfloat16_t>::sign_index() { template <> inline constexpr uint8_t binary_format<std::bfloat16_t>::sign_index() {
return 15; return 15;
} }
#endif #endif
template <> template <>
inline constexpr int binary_format<std::bfloat16_t>::largest_power_of_ten() { inline constexpr int16_t binary_format<std::bfloat16_t>::largest_power_of_ten() {
return 38; return 38;
} }
template <> template <>
inline constexpr int binary_format<std::bfloat16_t>::smallest_power_of_ten() { inline constexpr int16_t binary_format<std::bfloat16_t>::smallest_power_of_ten() {
return -60; return -60;
} }
template <> template <>
inline constexpr size_t binary_format<std::bfloat16_t>::max_digits() { inline constexpr uint16_t binary_format<std::bfloat16_t>::max_digits() {
return 98; return 98;
} }
#endif // __STDCPP_BFLOAT16_T__ #endif // __STDCPP_BFLOAT16_T__
@ -920,7 +922,7 @@ binary_format<double>::max_mantissa_fast_path(int64_t power) {
} }
template <> template <>
inline constexpr uint64_t inline constexpr uint32_t
binary_format<float>::max_mantissa_fast_path(int64_t power) { binary_format<float>::max_mantissa_fast_path(int64_t power) {
// caller is responsible to ensure that // caller is responsible to ensure that
FASTFLOAT_ASSUME(power >= 0 && power <= 10); FASTFLOAT_ASSUME(power >= 0 && power <= 10);
@ -948,28 +950,28 @@ inline constexpr float binary_format<float>::exact_power_of_ten(int64_t power) {
return (void)powers_of_ten[0], powers_of_ten[power]; return (void)powers_of_ten[0], powers_of_ten[power];
} }
template <> inline constexpr int binary_format<double>::largest_power_of_ten() { template <> inline constexpr int16_t binary_format<double>::largest_power_of_ten() {
return 308; return 308;
} }
template <> inline constexpr int binary_format<float>::largest_power_of_ten() { template <> inline constexpr int16_t binary_format<float>::largest_power_of_ten() {
return 38; return 38;
} }
template <> template <>
inline constexpr int binary_format<double>::smallest_power_of_ten() { inline constexpr int16_t binary_format<double>::smallest_power_of_ten() {
return -342; return -342;
} }
template <> inline constexpr int binary_format<float>::smallest_power_of_ten() { template <> inline constexpr int16_t binary_format<float>::smallest_power_of_ten() {
return -64; return -64;
} }
template <> inline constexpr size_t binary_format<double>::max_digits() { template <> inline constexpr uint16_t binary_format<double>::max_digits() {
return 769; return 769;
} }
template <> inline constexpr size_t binary_format<float>::max_digits() { template <> inline constexpr uint16_t binary_format<float>::max_digits() {
return 114; return 114;
} }