1#ifndef FASTFLOAT_FLOAT_COMMON_H
2#define FASTFLOAT_FLOAT_COMMON_H
10#if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) \
11 || defined(__amd64) || defined(__aarch64__) || defined(_M_ARM64) \
12 || defined(__MINGW64__) \
13 || defined(__s390x__) \
14 || (defined(__ppc64__) || defined(__PPC64__) || defined(__ppc64le__) || defined(__PPC64LE__)) )
15#define FASTFLOAT_64BIT
16#elif (defined(__i386) || defined(__i386__) || defined(_M_IX86) \
17 || defined(__arm__) || defined(_M_ARM) \
18 || defined(__MINGW32__) || defined(__EMSCRIPTEN__))
19#define FASTFLOAT_32BIT
24 #if SIZE_MAX == 0xffff
25 #error Unknown platform (16-bit, unsupported)
26 #elif SIZE_MAX == 0xffffffff
27 #define FASTFLOAT_32BIT
28 #elif SIZE_MAX == 0xffffffffffffffff
29 #define FASTFLOAT_64BIT
31 #error Unknown platform (not 32-bit, not 64-bit?)
35#if ((defined(_WIN32) || defined(_WIN64)) && !defined(__clang__))
39#if defined(_MSC_VER) && !defined(__clang__)
40#define FASTFLOAT_VISUAL_STUDIO 1
43#if defined __BYTE_ORDER__ && defined __ORDER_BIG_ENDIAN__
44#define FASTFLOAT_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
46#define FASTFLOAT_IS_BIG_ENDIAN 0
48#if defined(__APPLE__) || defined(__FreeBSD__)
49#include <machine/endian.h>
50#elif defined(sun) || defined(__sun)
51#include <sys/byteorder.h>
58#define FASTFLOAT_IS_BIG_ENDIAN 0
61#ifndef __ORDER_LITTLE_ENDIAN__
63#define FASTFLOAT_IS_BIG_ENDIAN 0
66#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
67#define FASTFLOAT_IS_BIG_ENDIAN 0
69#define FASTFLOAT_IS_BIG_ENDIAN 1
73#ifdef FASTFLOAT_VISUAL_STUDIO
74#define fastfloat_really_inline __forceinline
76#define fastfloat_really_inline inline __attribute__((always_inline))
79#ifndef FASTFLOAT_ASSERT
80#define FASTFLOAT_ASSERT(x) { if (!(x)) abort(); }
83#ifndef FASTFLOAT_DEBUG_ASSERT
85#define FASTFLOAT_DEBUG_ASSERT(x) assert(x)
89#define FASTFLOAT_TRY(x) { if (!(x)) return false; }
97 for (
size_t i = 0; i < length; i++) {
98 running_diff |= (input1[i] ^ input2[i]);
100 return (running_diff == 0) || (running_diff == 32);
103#ifndef FLT_EVAL_METHOD
104#error "FLT_EVAL_METHOD should be defined, please include cfloat."
115 constexpr size_t len() const noexcept {
134 assert(input_num > 0);
135#ifdef FASTFLOAT_VISUAL_STUDIO
136 #if defined(_M_X64) || defined(_M_ARM64)
137 unsigned long leading_zero = 0;
140 _BitScanReverse64(&leading_zero, input_num);
141 return (
int)(63 - leading_zero);
144 if(input_num & uint64_t(0xffffffff00000000)) input_num >>= 32, last_bit |= 32;
145 if(input_num & uint64_t( 0xffff0000)) input_num >>= 16, last_bit |= 16;
146 if(input_num & uint64_t( 0xff00)) input_num >>= 8, last_bit |= 8;
147 if(input_num & uint64_t( 0xf0)) input_num >>= 4, last_bit |= 4;
148 if(input_num & uint64_t( 0xc)) input_num >>= 2, last_bit |= 2;
149 if(input_num & uint64_t( 0x2)) input_num >>= 1, last_bit |= 1;
150 return 63 - last_bit;
153 return __builtin_clzll(input_num);
157#ifdef FASTFLOAT_32BIT
161 return x * (uint64_t)y;
165#if !defined(__MINGW64__)
168 uint64_t ad = emulu((uint32_t)(ab >> 32), (uint32_t)cd);
169 uint64_t bd = emulu((uint32_t)ab, (uint32_t)cd);
170 uint64_t adbc = ad + emulu((uint32_t)ab, (uint32_t)(cd >> 32));
171 uint64_t adbc_carry = !!(adbc < ad);
172 uint64_t lo = bd + (adbc << 32);
173 *hi = emulu((uint32_t)(ab >> 32), (uint32_t)(cd >> 32)) + (adbc >> 32) +
174 (adbc_carry << 32) + !!(lo < bd);
188 answer.
high = __umulh(a, b);
190#elif defined(FASTFLOAT_32BIT) || (defined(_WIN64) && !defined(__clang__))
191 answer.
low = _umul128(a, b, &answer.
high);
192#elif defined(FASTFLOAT_64BIT)
193 __uint128_t r = ((__uint128_t)a) * b;
194 answer.
low = uint64_t(r);
195 answer.
high = uint64_t(r >> 64);
197 #error Not implemented
218 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11,
219 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22};
221 1e6, 1e7, 1e8, 1e9, 1e10};
224 using equiv_uint =
typename std::conditional<
sizeof(T) == 4, uint32_t, uint64_t>::type;
285#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
292#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
307 return uint64_t(2) << mantissa_explicit_bits();
310 return uint64_t(2) << mantissa_explicit_bits();
355 return 0x7FF0000000000000;
364 return 0x000FFFFFFFFFFFFF;
373 return 0x0010000000000000;
382#if FASTFLOAT_IS_BIG_ENDIAN == 1
383 if (std::is_same<T, float>::value) {
384 ::memcpy(&value, (
char *)&word + 4,
sizeof(T));
386 ::memcpy(&value, &word,
sizeof(T));
390 ::memcpy(&value, &word,
sizeof(T));
#define FASTFLOAT_DEBUG_ASSERT(x)
#define fastfloat_really_inline
constexpr fastfloat_really_inline int32_t power(int32_t q) noexcept
fastfloat_really_inline void to_float(bool negative, adjusted_mantissa am, T &value)
fastfloat_really_inline int leading_zeroes(uint64_t input_num)
static constexpr int32_t invalid_am_bias
bool fastfloat_strncasecmp(const char *input1, const char *input2, size_t length)
static constexpr float powers_of_ten_float[]
fastfloat_really_inline value128 full_multiplication(uint64_t a, uint64_t b)
static constexpr double powers_of_ten_double[]
bool operator==(const adjusted_mantissa &o) const
adjusted_mantissa()=default
bool operator!=(const adjusted_mantissa &o) const
const T & operator[](size_t index) const noexcept
constexpr size_t len() const noexcept
span(const T *_ptr, size_t _length)
value128(uint64_t _low, uint64_t _high)