PostgreSQL Source Code  git master
ryu_common.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define STRICTLY_SHORTEST   0
 
#define RYU_32_BIT_PLATFORM
 

Functions

static uint32 pow5bits (const int32 e)
 
static int32 log10Pow2 (const int32 e)
 
static int32 log10Pow5 (const int32 e)
 
static int copy_special_str (char *const result, const bool sign, const bool exponent, const bool mantissa)
 
static uint32 float_to_bits (const float f)
 
static uint64 double_to_bits (const double d)
 

Macro Definition Documentation

◆ RYU_32_BIT_PLATFORM

#define RYU_32_BIT_PLATFORM

Definition at line 49 of file ryu_common.h.

◆ STRICTLY_SHORTEST

#define STRICTLY_SHORTEST   0

Definition at line 46 of file ryu_common.h.

Function Documentation

◆ copy_special_str()

static int copy_special_str ( char *const  result,
const bool  sign,
const bool  exponent,
const bool  mantissa 
)
inlinestatic

Definition at line 95 of file ryu_common.h.

References sign.

Referenced by double_to_shortest_decimal_bufn(), and float_to_shortest_decimal_bufn().

96 {
97  if (mantissa)
98  {
99  memcpy(result, "NaN", 3);
100  return 3;
101  }
102  if (sign)
103  {
104  result[0] = '-';
105  }
106  if (exponent)
107  {
108  memcpy(result + sign, "Infinity", 8);
109  return sign + 8;
110  }
111  result[sign] = '0';
112  return sign + 1;
113 }
char sign
Definition: informix.c:668

◆ double_to_bits()

static uint64 double_to_bits ( const double  d)
inlinestatic

Definition at line 125 of file ryu_common.h.

Referenced by double_to_shortest_decimal_bufn().

126 {
127  uint64 bits = 0;
128 
129  memcpy(&bits, &d, sizeof(double));
130  return bits;
131 }

◆ float_to_bits()

static uint32 float_to_bits ( const float  f)
inlinestatic

Definition at line 116 of file ryu_common.h.

Referenced by float_to_shortest_decimal_bufn().

117 {
118  uint32 bits = 0;
119 
120  memcpy(&bits, &f, sizeof(float));
121  return bits;
122 }
unsigned int uint32
Definition: c.h:367

◆ log10Pow2()

static int32 log10Pow2 ( const int32  e)
inlinestatic

Definition at line 70 of file ryu_common.h.

References Assert.

Referenced by d2d(), and f2d().

71 {
72  /*
73  * The first value this approximation fails for is 2^1651 which is just
74  * greater than 10^297.
75  */
76  Assert(e >= 0);
77  Assert(e <= 1650);
78  return (int32) ((((uint32) e) * 78913) >> 18);
79 }
signed int int32
Definition: c.h:355
unsigned int uint32
Definition: c.h:367
#define Assert(condition)
Definition: c.h:738
e
Definition: preproc-init.c:82

◆ log10Pow5()

static int32 log10Pow5 ( const int32  e)
inlinestatic

Definition at line 83 of file ryu_common.h.

References Assert.

Referenced by d2d(), and f2d().

84 {
85  /*
86  * The first value this approximation fails for is 5^2621 which is just
87  * greater than 10^1832.
88  */
89  Assert(e >= 0);
90  Assert(e <= 2620);
91  return (int32) ((((uint32) e) * 732923) >> 20);
92 }
signed int int32
Definition: c.h:355
unsigned int uint32
Definition: c.h:367
#define Assert(condition)
Definition: c.h:738
e
Definition: preproc-init.c:82

◆ pow5bits()

static uint32 pow5bits ( const int32  e)
inlinestatic

Definition at line 54 of file ryu_common.h.

References Assert.

Referenced by d2d(), and f2d().

55 {
56  /*
57  * This approximation works up to the point that the multiplication
58  * overflows at e = 3529.
59  *
60  * If the multiplication were done in 64 bits, it would fail at 5^4004
61  * which is just greater than 2^9297.
62  */
63  Assert(e >= 0);
64  Assert(e <= 3528);
65  return ((((uint32) e) * 1217359) >> 19) + 1;
66 }
unsigned int uint32
Definition: c.h:367
#define Assert(condition)
Definition: c.h:738
e
Definition: preproc-init.c:82