Ruby: missing/dtoa.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Typedefs | Functions
dtoa.c File Reference
`#include <limits.h>`
`#include <ctype.h>`
`#include <errno.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <float.h>`
`#include <math.h>`

Go to the source code of this file.

## Data Structures
union | U
struct | Bigint

## Macros
#define | IEEE_LITTLE_ENDIAN
#define | NO_LONG_LONG
#define | ISDIGIT(c) isdigit(c)
#define | MALLOC xmalloc
#define | FREE xfree
#define | NO_SANITIZE(x, y) y
#define | PRIVATE_MEM 2304
#define | PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
#define | IEEE_Arith
#define | word0(x) ((x).L[1])
#define | word1(x) ((x).L[0])
#define | dval(x) ((x).d)
#define | Storeinc(a, b, c)
#define | Exp_shift 20
#define | Exp_shift1 20
#define | Exp_msk1 0x100000
#define | Exp_msk11 0x100000
#define | Exp_mask 0x7ff00000
#define | P 53
#define | Bias 1023
#define | Emin (-1022)
#define | Exp_1 0x3ff00000
#define | Exp_11 0x3ff00000
#define | Ebits 11
#define | Frac_mask 0xfffff
#define | Frac_mask1 0xfffff
#define | Ten_pmax 22
#define | Bletch 0x10
#define | Bndry_mask 0xfffff
#define | Bndry_mask1 0xfffff
#define | LSB 1
#define | Sign_bit 0x80000000
#define | Log2P 1
#define | Tiny0 0
#define | Tiny1 1
#define | Quick_max 14
#define | Int_max 14
#define | Avoid_Underflow
#define | Flt_Rounds 1
#define | Rounding Flt_Rounds
#define | rounded_product(a, b) ((a) *= (b))
#define | rounded_quotient(a, b) ((a) /= (b))
#define | Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
#define | Big1 0xffffffff
#define | Pack_32
#define | FFFFFFFF 0xffffffffUL
#define | MULTIPLE_THREADS 1
#define | ACQUIRE_DTOA_LOCK(n) /*unused right now*/
#define | FREE_DTOA_LOCK(n) /*unused right now*/
#define | ATOMIC_PTR_CAS(var, old, new) ((var) = (new), (old))
#define | LIKELY(x) (x)
#define | UNLIKELY(x) (x)
#define | ASSUME(x) (void)(x)
#define | Kmax 15
#define | BLOCKING_BIGINT ((Bigint *)(-1))
#define | Bcopy(x, y)
#define | d0 word0(d)
#define | d1 word1(d)
#define | d0 word0(d)
#define | d1 word1(d)
#define | Scale_Bit 0x10
#define | n_bigtens 5
#define | rv_alloc(i) MALLOC(i)
#define | rv_strdup(s, rve) nrv_alloc((s), (rve), strlen(s)+1)
#define | DBL_MANH_SIZE 20
#define | DBL_MANL_SIZE 32
#define | DBL_ADJ (DBL_MAX_EXP - 2)
#define | SIGFIGS ((DBL_MANT_DIG + 3) / 4 + 1)
#define | dexp_get(u) ((int)(word0(u) >> Exp_shift) & ~Exp_msk1)
#define | dexp_set(u, v) (word0(u) = (((int)(word0(u)) & ~Exp_mask) | ((v) << Exp_shift)))
#define | dmanh_get(u) ((uint32_t)(word0(u) & Frac_mask))
#define | dmanl_get(u) ((uint32_t)word1(u))

## Typedefs
typedef U | double_u
typedef struct Bigint | Bigint

## Functions
| NO_SANITIZE ("unsigned-integer-overflow", static Bigint *diff(Bigint *a, Bigint *b))
| NO_SANITIZE ("unsigned-integer-overflow", double strtod(const char *s00, char **se))
double | strtod (const char *s00, char **se)
| NO_SANITIZE ("unsigned-integer-overflow", static int quorem(Bigint *b, Bigint *S))
char * | dtoa (double d_, int mode, int ndigits, int *decpt, int *sign, char **rve)
char * | hdtoa (double d, const char *xdigs, int ndigits, int *decpt, int *sign, char **rve)

## Macro Definition Documentation

## ◆ ACQUIRE_DTOA_LOCK

#define ACQUIRE_DTOA_LOCK | ( |  | n | ) | /*unused right now*/

Definition at line 500 of file dtoa.c.

## ◆ ASSUME

#define ASSUME | ( |  | x | ) | (void)(x)

Definition at line 514 of file dtoa.c.

## ◆ ATOMIC_PTR_CAS

#define ATOMIC_PTR_CAS | ( |  | var,
|  |  | old,
|  |  | new
| ) |  | ((var) = (new), (old))

Definition at line 505 of file dtoa.c.

## ◆ Avoid_Underflow

#define Avoid_Underflow

Definition at line 370 of file dtoa.c.

## ◆ Bcopy

#define Bcopy | ( |  | x,
|  |  | y
| ) |  |

Value:
memcpy((char *)&(x)->sign, (char *)&(y)->sign, \
(y)->wds*sizeof(Long) + 2*sizeof(int))
memcpy
#define memcpy(d, s, n)
Definition: ffi_common.h:55

Definition at line 605 of file dtoa.c.

## ◆ Bias

#define Bias 1023

Definition at line 351 of file dtoa.c.

## ◆ Big0

#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))

Definition at line 466 of file dtoa.c.

## ◆ Big1

#define Big1 0xffffffff

Definition at line 467 of file dtoa.c.

## ◆ Bletch

#define Bletch 0x10

Definition at line 359 of file dtoa.c.

## ◆ BLOCKING_BIGINT

#define BLOCKING_BIGINT ((Bigint *)(-1))

Definition at line 529 of file dtoa.c.

## ◆ Bndry_mask

#define Bndry_mask 0xfffff

Definition at line 360 of file dtoa.c.

## ◆ Bndry_mask1

#define Bndry_mask1 0xfffff

Definition at line 361 of file dtoa.c.

## ◆ d0 [1/2]

#define d0 word0(d)

## ◆ d0 [2/2]

#define d0 word0(d)

## ◆ d1 [1/2]

#define d1 word1(d)

## ◆ d1 [2/2]

#define d1 word1(d)

## ◆ DBL_ADJ

#define DBL_ADJ (DBL_MAX_EXP - 2)

Definition at line 3354 of file dtoa.c.

## ◆ DBL_MANH_SIZE

#define DBL_MANH_SIZE 20

Definition at line 3352 of file dtoa.c.

## ◆ DBL_MANL_SIZE

#define DBL_MANL_SIZE 32

Definition at line 3353 of file dtoa.c.

## ◆ dexp_get

#define dexp_get | ( |  | u | ) | ((int)(word0(u) >> Exp_shift) & ~Exp_msk1)

Definition at line 3356 of file dtoa.c.

## ◆ dexp_set

#define dexp_set | ( |  | u,
|  |  | v
| ) |  | (word0(u) = (((int)(word0(u)) & ~Exp_mask) | ((v) << Exp_shift)))

Definition at line 3357 of file dtoa.c.

## ◆ dmanh_get

#define dmanh_get | ( |  | u | ) | ((uint32_t)(word0(u) & Frac_mask))

Definition at line 3358 of file dtoa.c.

## ◆ dmanl_get

#define dmanl_get | ( |  | u | ) | ((uint32_t)word1(u))

Definition at line 3359 of file dtoa.c.

## ◆ dval

#define dval | ( |  | x | ) | ((x).d)

Definition at line 323 of file dtoa.c.

## ◆ Ebits

#define Ebits 11

Definition at line 355 of file dtoa.c.

## ◆ Emin

#define Emin (-1022)

Definition at line 352 of file dtoa.c.

## ◆ Exp_1

#define Exp_1 0x3ff00000

Definition at line 353 of file dtoa.c.

## ◆ Exp_11

#define Exp_11 0x3ff00000

Definition at line 354 of file dtoa.c.

## ◆ Exp_mask

#define Exp_mask 0x7ff00000

Definition at line 349 of file dtoa.c.

## ◆ Exp_msk1

#define Exp_msk1 0x100000

Definition at line 347 of file dtoa.c.

## ◆ Exp_msk11

#define Exp_msk11 0x100000

Definition at line 348 of file dtoa.c.

## ◆ Exp_shift

#define Exp_shift 20

Definition at line 345 of file dtoa.c.

## ◆ Exp_shift1

#define Exp_shift1 20

Definition at line 346 of file dtoa.c.

## ◆ FFFFFFFF

#define FFFFFFFF 0xffffffffUL

Definition at line 473 of file dtoa.c.

## ◆ Flt_Rounds

#define Flt_Rounds 1

Definition at line 380 of file dtoa.c.

## ◆ Frac_mask

#define Frac_mask 0xfffff

Definition at line 356 of file dtoa.c.

## ◆ Frac_mask1

#define Frac_mask1 0xfffff

Definition at line 357 of file dtoa.c.

## ◆ FREE

#define FREE xfree

Definition at line 229 of file dtoa.c.

## ◆ FREE_DTOA_LOCK

#define FREE_DTOA_LOCK | ( |  | n | ) | /*unused right now*/

Definition at line 501 of file dtoa.c.

## ◆ IEEE_Arith

#define IEEE_Arith

Definition at line 249 of file dtoa.c.

## ◆ IEEE_LITTLE_ENDIAN

#define IEEE_LITTLE_ENDIAN

Definition at line 169 of file dtoa.c.

## ◆ Int_max

#define Int_max 14

Definition at line 368 of file dtoa.c.

## ◆ ISDIGIT

#define ISDIGIT | ( |  | c | ) | isdigit(c)

Definition at line 211 of file dtoa.c.

## ◆ Kmax

#define Kmax 15

Definition at line 517 of file dtoa.c.

## ◆ LIKELY

#define LIKELY | ( |  | x | ) | (x)

Definition at line 508 of file dtoa.c.

## ◆ Log2P

#define Log2P 1

Definition at line 364 of file dtoa.c.

## ◆ LSB

#define LSB 1

Definition at line 362 of file dtoa.c.

## ◆ MALLOC

#define MALLOC xmalloc

Definition at line 224 of file dtoa.c.

## ◆ MULTIPLE_THREADS

#define MULTIPLE_THREADS 1

Definition at line 494 of file dtoa.c.

## ◆ n_bigtens

#define n_bigtens 5

Definition at line 1402 of file dtoa.c.

## ◆ NO_LONG_LONG

#define NO_LONG_LONG

Definition at line 201 of file dtoa.c.

## ◆ NO_SANITIZE

#define NO_SANITIZE | ( |  | x,
|  |  | y
| ) |  | y

Definition at line 232 of file dtoa.c.

## ◆ P

#define P 53

Definition at line 350 of file dtoa.c.

## ◆ Pack_32

#define Pack_32

Definition at line 470 of file dtoa.c.

## ◆ PRIVATE_MEM

#define PRIVATE_MEM 2304

Definition at line 237 of file dtoa.c.

## ◆ PRIVATE_mem

#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))

Definition at line 239 of file dtoa.c.

## ◆ Quick_max

#define Quick_max 14

Definition at line 367 of file dtoa.c.

## ◆ rounded_product

#define rounded_product | ( |  | a,
|  |  | b
| ) |  | ((a) *= (b))

Definition at line 462 of file dtoa.c.

## ◆ rounded_quotient

#define rounded_quotient | ( |  | a,
|  |  | b
| ) |  | ((a) /= (b))

Definition at line 463 of file dtoa.c.

## ◆ Rounding

#define Rounding Flt_Rounds

Definition at line 389 of file dtoa.c.

## ◆ rv_alloc

#define rv_alloc | ( |  | i | ) | MALLOC(i)

Definition at line 2579 of file dtoa.c.

## ◆ rv_strdup

#define rv_strdup | ( |  | s,
|  |  | rve
| ) |  | nrv_alloc((s), (rve), strlen(s)+1)

Definition at line 2594 of file dtoa.c.

## ◆ Scale_Bit

#define Scale_Bit 0x10

Definition at line 1401 of file dtoa.c.

## ◆ SIGFIGS

#define SIGFIGS ((DBL_MANT_DIG + 3) / 4 + 1)

Definition at line 3355 of file dtoa.c.

## ◆ Sign_bit

#define Sign_bit 0x80000000

Definition at line 363 of file dtoa.c.

## ◆ Storeinc

#define Storeinc | ( |  | a,
|  |  | b,
|  |  | c
| ) |  |

Value:
(((unsigned short *)(a))[1] = (unsigned short)(b), \
((unsigned short *)(a))[0] = (unsigned short)(c), (a)++)

Definition at line 331 of file dtoa.c.

## ◆ Ten_pmax

#define Ten_pmax 22

Definition at line 358 of file dtoa.c.

## ◆ Tiny0

#define Tiny0 0

Definition at line 365 of file dtoa.c.

## ◆ Tiny1

#define Tiny1 1

Definition at line 366 of file dtoa.c.

## ◆ UNLIKELY

#define UNLIKELY | ( |  | x | ) | (x)

Definition at line 511 of file dtoa.c.

## ◆ word0

#define word0 | ( |  | x | ) | ((x).L[1])

Definition at line 317 of file dtoa.c.

## ◆ word1

#define word1 | ( |  | x | ) | ((x).L[0])

Definition at line 318 of file dtoa.c.

## Typedef Documentation

## ◆ Bigint

typedef struct Bigint Bigint

Definition at line 525 of file dtoa.c.

## ◆ double_u

typedef U double_u

Definition at line 315 of file dtoa.c.

## Function Documentation

## ◆ dtoa()

char * dtoa | ( | double | d_,
|  | int | mode,
|  | int | ndigits,
|  | int * | decpt,
|  | int * | sign,
|  | char ** | rve
| ) |  |

Definition at line 2649 of file dtoa.c.

References Bcopy, Bias, Bletch, Bndry_mask, dval, Exp_1, Exp_11, Exp_mask, Exp_msk1, Exp_shift, Exp_shift1, Flt_Rounds, Frac_mask, Frac_mask1, int(), Int_max, Bigint::k, L, Log2P, n_bigtens, P, Quick_max, Rounding, rv_alloc, rv_strdup, S, Bigint::sign, Sign_bit, Ten_pmax, Bigint::wds, word0, word1, and Bigint::x.

## ◆ hdtoa()

char * hdtoa | ( | double | d,
|  | const char * | xdigs,
|  | int | ndigits,
|  | int * | decpt,
|  | int * | sign,
|  | char ** | rve
| ) |  |

Definition at line 3387 of file dtoa.c.

References U::d, DBL_ADJ, DBL_MANH_SIZE, DBL_MANL_SIZE, DBL_MANT_DIG, DBL_MAX_EXP, dexp_get, dexp_set, dmanh_get, dmanl_get, isinf(), isnan, NULL, rv_alloc, rv_strdup, SIGFIGS, Bigint::sign, Sign_bit, and word0.

## ◆ NO_SANITIZE() [1/3]

NO_SANITIZE | ( | "unsigned-integer-overflow" | ,
|  | double | strtodconst char *s00, char **se
| ) |  |

## ◆ NO_SANITIZE() [2/3]

NO_SANITIZE | ( | "unsigned-integer-overflow" | ,
|  | static Bigint * | diffBigint *a, Bigint *b
| ) |  |

## ◆ NO_SANITIZE() [3/3]

NO_SANITIZE | ( | "unsigned-integer-overflow" | ,
|  | static int | quoremBigint *b, Bigint *S
| ) |  |

## ◆ strtod()

double strtod | ( | const char * | s00,
|  | char ** | se
| ) |  |

Definition at line 1497 of file dtoa.c.

References Avoid_Underflow, Bcopy, Bias, Big0, Big1, Bndry_mask, Bndry_mask1, DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP, dval, Emin, Exp_1, Exp_mask, Exp_msk1, Exp_shift, FLT_RADIX, Flt_Rounds, Frac_mask, hexdigit, IEEE_Arith, int(), ISDIGIT, Bigint::k, L, Log2P, LSB, match, n_bigtens, NULL, P, rounded_product, rounded_quotient, Rounding, Scale_Bit, Bigint::sign, strchr(), Ten_pmax, Tiny0, Tiny1, Bigint::wds, word0, word1, and Bigint::x.