Skip to content

Commit da819fe

Browse files
committed
back to std::bit_cast
1 parent 3b9ff76 commit da819fe

File tree

2 files changed

+63
-49
lines changed

2 files changed

+63
-49
lines changed

include/fast_float/digit_comparison.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ to_extended(T value) noexcept {
7272
binary_format<T>::minimum_exponent();
7373
equiv_uint bits;
7474
#if FASTFLOAT_HAS_BIT_CAST
75-
bits = bit_cast<equiv_uint>(value);
75+
bits = std::bit_cast<equiv_uint>(value);
7676
#else
7777
::memcpy(&bits, &value, sizeof(T));
7878
#endif

include/fast_float/float_common.h

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ struct is_supported_char_type
260260
> {
261261
};
262262

263+
#if 0
263264
union float_union {
264265
float f;
265266
uint32_t bits;
@@ -341,6 +342,7 @@ fastfloat_really_inline constexpr std::bfloat16_t bit_cast(const uint16_t &u) {
341342
return fu.f;
342343
}
343344
#endif // __STDCPP_BFLOAT16_T__
345+
#endif // 0
344346

345347
// Compares two ASCII strings in a case insensitive manner.
346348
template <typename UC>
@@ -519,25 +521,25 @@ template <typename T, typename U = void> struct binary_format_lookup_tables;
519521
template <typename T> struct binary_format : binary_format_lookup_tables<T> {
520522
using equiv_uint = equiv_uint_t<T>;
521523

522-
static inline constexpr int mantissa_explicit_bits();
523-
static inline constexpr int minimum_exponent();
524-
static inline constexpr int infinite_power();
525-
static inline constexpr int sign_index();
526-
static inline constexpr int
524+
static constexpr int mantissa_explicit_bits();
525+
static constexpr int minimum_exponent();
526+
static constexpr int infinite_power();
527+
static constexpr int sign_index();
528+
static constexpr int
527529
min_exponent_fast_path(); // used when fegetround() == FE_TONEAREST
528-
static inline constexpr int max_exponent_fast_path();
529-
static inline constexpr int max_exponent_round_to_even();
530-
static inline constexpr int min_exponent_round_to_even();
531-
static inline constexpr uint64_t max_mantissa_fast_path(int64_t power);
532-
static inline constexpr uint64_t
530+
static constexpr int max_exponent_fast_path();
531+
static constexpr int max_exponent_round_to_even();
532+
static constexpr int min_exponent_round_to_even();
533+
static constexpr uint64_t max_mantissa_fast_path(int64_t power);
534+
static constexpr uint64_t
533535
max_mantissa_fast_path(); // used when fegetround() == FE_TONEAREST
534-
static inline constexpr int largest_power_of_ten();
535-
static inline constexpr int smallest_power_of_ten();
536-
static inline constexpr T exact_power_of_ten(int64_t power);
537-
static inline constexpr size_t max_digits();
538-
static inline constexpr equiv_uint exponent_mask();
539-
static inline constexpr equiv_uint mantissa_mask();
540-
static inline constexpr equiv_uint hidden_bit_mask();
536+
static constexpr int largest_power_of_ten();
537+
static constexpr int smallest_power_of_ten();
538+
static constexpr T exact_power_of_ten(int64_t power);
539+
static constexpr size_t max_digits();
540+
static constexpr equiv_uint exponent_mask();
541+
static constexpr equiv_uint mantissa_mask();
542+
static constexpr equiv_uint hidden_bit_mask();
541543
};
542544

543545
template <typename U> struct binary_format_lookup_tables<double, U> {
@@ -710,6 +712,11 @@ inline constexpr uint64_t binary_format<double>::max_mantissa_fast_path() {
710712
return uint64_t(2) << mantissa_explicit_bits();
711713
}
712714

715+
template <>
716+
inline constexpr uint64_t binary_format<float>::max_mantissa_fast_path() {
717+
return uint64_t(2) << mantissa_explicit_bits();
718+
}
719+
713720
// credit: Jakub Jelínek
714721
#ifdef __STDCPP_FLOAT16_T__
715722
template <typename U> struct binary_format_lookup_tables<std::float16_t, U> {
@@ -768,6 +775,11 @@ inline constexpr int binary_format<std::float16_t>::max_exponent_fast_path() {
768775
return 4;
769776
}
770777

778+
template <>
779+
inline constexpr int binary_format<std::float16_t>::mantissa_explicit_bits() {
780+
return 10;
781+
}
782+
771783
template <>
772784
inline constexpr uint64_t
773785
binary_format<std::float16_t>::max_mantissa_fast_path() {
@@ -790,43 +802,43 @@ inline constexpr int binary_format<std::float16_t>::min_exponent_fast_path() {
790802
}
791803

792804
template <>
793-
constexpr int binary_format<std::float16_t>::mantissa_explicit_bits() {
794-
return 10;
795-
}
796-
797-
template <>
798-
constexpr int binary_format<std::float16_t>::max_exponent_round_to_even() {
805+
inline constexpr int
806+
binary_format<std::float16_t>::max_exponent_round_to_even() {
799807
return 5;
800808
}
801809

802810
template <>
803-
constexpr int binary_format<std::float16_t>::min_exponent_round_to_even() {
811+
inline constexpr int
812+
binary_format<std::float16_t>::min_exponent_round_to_even() {
804813
return -22;
805814
}
806815

807-
template <> constexpr int binary_format<std::float16_t>::minimum_exponent() {
816+
template <>
817+
inline constexpr int binary_format<std::float16_t>::minimum_exponent() {
808818
return -15;
809819
}
810820

811-
template <> constexpr int binary_format<std::float16_t>::infinite_power() {
821+
template <>
822+
inline constexpr int binary_format<std::float16_t>::infinite_power() {
812823
return 0x1F;
813824
}
814825

815-
template <> constexpr int binary_format<std::float16_t>::sign_index() {
826+
template <> inline constexpr int binary_format<std::float16_t>::sign_index() {
816827
return 15;
817828
}
818829

819830
template <>
820-
constexpr int binary_format<std::float16_t>::largest_power_of_ten() {
831+
inline constexpr int binary_format<std::float16_t>::largest_power_of_ten() {
821832
return 4;
822833
}
823834

824835
template <>
825-
constexpr int binary_format<std::float16_t>::smallest_power_of_ten() {
836+
inline constexpr int binary_format<std::float16_t>::smallest_power_of_ten() {
826837
return -27;
827838
}
828839

829-
template <> constexpr size_t binary_format<std::float16_t>::max_digits() {
840+
template <>
841+
inline constexpr size_t binary_format<std::float16_t>::max_digits() {
830842
return 22;
831843
}
832844

@@ -887,6 +899,11 @@ binary_format<std::bfloat16_t>::hidden_bit_mask() {
887899
return 0x0080;
888900
}
889901

902+
template <>
903+
inline constexpr int binary_format<std::bfloat16_t>::mantissa_explicit_bits() {
904+
return 7;
905+
}
906+
890907
template <>
891908
inline constexpr uint64_t
892909
binary_format<std::bfloat16_t>::max_mantissa_fast_path() {
@@ -909,43 +926,43 @@ inline constexpr int binary_format<std::bfloat16_t>::min_exponent_fast_path() {
909926
}
910927

911928
template <>
912-
constexpr int binary_format<std::bfloat16_t>::mantissa_explicit_bits() {
913-
return 7;
914-
}
915-
916-
template <>
917-
constexpr int binary_format<std::bfloat16_t>::max_exponent_round_to_even() {
929+
inline constexpr int
930+
binary_format<std::bfloat16_t>::max_exponent_round_to_even() {
918931
return 3;
919932
}
920933

921934
template <>
922-
constexpr int binary_format<std::bfloat16_t>::min_exponent_round_to_even() {
935+
inline constexpr int
936+
binary_format<std::bfloat16_t>::min_exponent_round_to_even() {
923937
return -24;
924938
}
925939

926-
template <> constexpr int binary_format<std::bfloat16_t>::minimum_exponent() {
940+
template <>
941+
inline constexpr int binary_format<std::bfloat16_t>::minimum_exponent() {
927942
return -127;
928943
}
929944

930-
template <> constexpr int binary_format<std::bfloat16_t>::infinite_power() {
945+
template <>
946+
inline constexpr int binary_format<std::bfloat16_t>::infinite_power() {
931947
return 0xFF;
932948
}
933949

934-
template <> constexpr int binary_format<std::bfloat16_t>::sign_index() {
950+
template <> inline constexpr int binary_format<std::bfloat16_t>::sign_index() {
935951
return 15;
936952
}
937953

938954
template <>
939-
constexpr int binary_format<std::bfloat16_t>::largest_power_of_ten() {
955+
inline constexpr int binary_format<std::bfloat16_t>::largest_power_of_ten() {
940956
return 38;
941957
}
942958

943959
template <>
944-
constexpr int binary_format<std::bfloat16_t>::smallest_power_of_ten() {
960+
inline constexpr int binary_format<std::bfloat16_t>::smallest_power_of_ten() {
945961
return -60;
946962
}
947963

948-
template <> constexpr size_t binary_format<std::bfloat16_t>::max_digits() {
964+
template <>
965+
inline constexpr size_t binary_format<std::bfloat16_t>::max_digits() {
949966
return 98;
950967
}
951968

@@ -961,11 +978,6 @@ binary_format<double>::max_mantissa_fast_path(int64_t power) {
961978
return (void)max_mantissa[0], max_mantissa[power];
962979
}
963980

964-
template <>
965-
inline constexpr uint64_t binary_format<float>::max_mantissa_fast_path() {
966-
return uint64_t(2) << mantissa_explicit_bits();
967-
}
968-
969981
template <>
970982
inline constexpr uint64_t
971983
binary_format<float>::max_mantissa_fast_path(int64_t power) {
@@ -1064,6 +1076,7 @@ to_float(bool negative, adjusted_mantissa am, T &value) {
10641076
#endif
10651077
}
10661078

1079+
#if 0
10671080
#ifdef __STDCPP_FLOAT16_T__
10681081
template <>
10691082
fastfloat_really_inline void to_float<std::float16_t>(bool negative,
@@ -1091,6 +1104,7 @@ fastfloat_really_inline void to_float<std::bfloat16_t>(bool negative,
10911104
}
10921105

10931106
#endif // __STDCPP_BFLOAT16_T__
1107+
#endif // 0
10941108

10951109
template <typename = void> struct space_lut {
10961110
static constexpr bool value[] = {

0 commit comments

Comments
 (0)