Conscience Core
Classes | Namespaces | Macros | Functions
fast_double_parser.h File Reference
#include <cfloat>
#include <cinttypes>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <locale.h>

Go to the source code of this file.

Classes

struct  fast_double_parser::value128
 

Namespaces

 fast_double_parser
 

Macros

#define WARN_UNUSED   __attribute__((warn_unused_result))
 
#define FASTFLOAT_SMALLEST_POWER   -325
 
#define FASTFLOAT_LARGEST_POWER   308
 
#define unlikely(x)   __builtin_expect(!!(x), 0)
 
#define really_inline   __attribute__((always_inline)) inline
 

Functions

really_inline uint64_t fast_double_parser::Emulate64x64to128 (uint64_t &r_hi, const uint64_t x, const uint64_t y)
 
really_inline value128 fast_double_parser::full_multiplication (uint64_t value1, uint64_t value2)
 
int fast_double_parser::leading_zeroes (uint64_t input_num)
 
static bool fast_double_parser::is_integer (char c)
 
really_inline double fast_double_parser::compute_float_64 (int64_t power, uint64_t i, bool negative, bool *success)
 
static const char * fast_double_parser::parse_float_strtod (const char *ptr, double *outDouble)
 
WARN_UNUSED const really_inline char * fast_double_parser::parse_number (const char *p, double *outDouble)
 

Macro Definition Documentation

◆ FASTFLOAT_LARGEST_POWER

#define FASTFLOAT_LARGEST_POWER   308

◆ FASTFLOAT_SMALLEST_POWER

#define FASTFLOAT_SMALLEST_POWER   -325

The smallest non-zero float (binary64) is 2^−1074. We take as input numbers of the form w x 10^q where w < 2^64. We have that w * 10^-343 < 2^(64-344) 5^-343 < 2^-1076. However, we have that (2^64-1) * 10^-342 = (2^64-1) * 2^-342 * 5^-342 > 2^−1074. Thus it is possible for a number of the form w * 10^-342 where w is a 64-bit value to be a non-zero floating-point number.

If we are solely interested in the normal numbers then the smallest value is 2^-1022. We can generate a value larger than 2^-1022 with expressions of the form w * 10^-326. Thus we need to pick FASTFLOAT_SMALLEST_POWER >= -326.

Any number of form w * 10^309 where w>= 1 is going to be infinite in binary64 so we never need to worry about powers of 5 greater than 308.

◆ really_inline

#define really_inline   __attribute__((always_inline)) inline

◆ unlikely

#define unlikely (   x)    __builtin_expect(!!(x), 0)

◆ WARN_UNUSED

#define WARN_UNUSED   __attribute__((warn_unused_result))

Determining whether we should import xlocale.h or not is a bit of a nightmare.