util.c File Reference
`#include "ruby/ruby.h"`
`#include "internal.h"`
`#include <ctype.h>`
`#include <stdio.h>`
`#include <errno.h>`
`#include <math.h>`
`#include <float.h>`
`#include "missing/file.h"`
`#include "ruby/util.h"`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include "stdlib.h"`
`#include "string.h"`

Go to the source code of this file.

## Data Structures

struct | stack_node
union | U
struct | Bigint

## Macros

#define | S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define | A ((int*)a)
#define | B ((int*)b)
#define | C ((int*)c)
#define | D ((int*)d)
#define | mmprepare(base, size)
#define | mmarg mmkind, size, high, low
#define | mmswap(a, b) mmswap_((a),(b),mmarg)
#define | mmrot3(a, b, c) mmrot3_((a),(b),(c),mmarg)
#define | PUSH(ll, rr) do { top->LL = (ll); top->RR = (rr); ++top; } while (0) /* Push L,l,R,r */
#define | POP(ll, rr) do { --top; (ll) = top->LL; (rr) = top->RR; } while (0) /* Pop L,l,R,r */
#define | med3(a, b, c)
#define | PATH_MAX 8192
#define | IEEE_LITTLE_ENDIAN
#define | MALLOC malloc
#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 | Llong long long
#define | ULLong unsigned Llong
#define | MULTIPLE_THREADS 1
#define | ACQUIRE_DTOA_LOCK(n) /*unused right now*/
#define | FREE_DTOA_LOCK(n) /*unused right now*/
#define | Kmax 15
#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) xmalloc(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

unsigned long | ruby_scan_oct (const char *start, size_t len, size_t *retlen)
unsigned long | ruby_scan_hex (const char *start, size_t len, size_t *retlen)
static unsigned long | scan_digits (const char *str, int base, size_t *retlen, int *overflow)
unsigned long | ruby_strtoul (const char *str, char **endptr, int base)
static void | mmswap_ (register char *a, register char *b, int mmkind, size_t size, size_t high, size_t low)
static void | mmrot3_ (register char *a, register char *b, register char *c, int mmkind, size_t size, size_t high, size_t low)
void | ruby_qsort (void *base, const size_t nel, const size_t size, int(*cmp)(const void *, const void *, void *), void *d)
char * | ruby_strdup (const char *str)
char * | ruby_getcwd (void)
static Bigint * | Balloc (int k)
static void | Bfree (Bigint *v)
static Bigint * | multadd (Bigint *b, int m, int a)
static Bigint * | s2b (const char *s, int nd0, int nd, ULong y9)
static int | hi0bits (register ULong x)
static int | lo0bits (ULong *y)
static Bigint * | i2b (int i)
static Bigint * | mult (Bigint *a, Bigint *b)
static Bigint * | pow5mult (Bigint *b, int k)
static Bigint * | lshift (Bigint *b, int k)
static int | cmp (Bigint *a, Bigint *b)
static Bigint * | diff (Bigint *a, Bigint *b)
static double | ulp (double x_)
static double | b2d (Bigint *a, int *e)
static Bigint * | d2b (double d_, int *e, int *bits)
static double | ratio (Bigint *a, Bigint *b)
double | ruby_strtod (const char *s00, char **se)
static int | quorem (Bigint *b, Bigint *S)
static char * | nrv_alloc (const char *s, char **rve, size_t n)
char * | ruby_dtoa (double d_, int mode, int ndigits, int *decpt, int *sign, char **rve)
void | ruby_each_words (const char *str, void(*func)(const char *, int, void *), void *arg)
char * | ruby_hdtoa (double d, const char *xdigs, int ndigits, int *decpt, int *sign, char **rve)

## Variables

static double | private_mem [PRIVATE_mem]
static double * | pmem_next = private_mem
static Bigint * | freelist [Kmax+1]
static Bigint * | p5s
static const double | tens []
static const double | bigtens [] = { 1e16, 1e32, 1e64, 1e128, 1e256 }
static const double | tinytens []
static const char | INFSTR [] = "Infinity"
static const char | NANSTR [] = "NaN"
static const char | ZEROSTR [] = "0"

## Macro Definition Documentation

#define A ((int*)a)

Definition at line 368 of file util.c.

Referenced by mmrot3_(), and mmswap_().

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

Definition at line 1119 of file util.c.

Referenced by Balloc(), Bfree(), and pow5mult().

#define Avoid_Underflow

Definition at line 989 of file util.c.

Referenced by ruby_strtod().

#define B ((int*)b)

Definition at line 369 of file util.c.

Referenced by des_cipher(), mmrot3_(), and mmswap_().

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

Value:
memcpy((char *)&(x)->sign, (char *)&(y)->sign, \
(y)->wds*sizeof(Long) + 2*sizeof(int))

Definition at line 1181 of file util.c.

Referenced by multadd(), ruby_dtoa(), and ruby_strtod().

#define Bias 1023

Definition at line 970 of file util.c.

Referenced by d2b(), ruby_dtoa(), and ruby_strtod().

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

Definition at line 1085 of file util.c.

Referenced by ruby_strtod().

#define Big1 0xffffffff

Definition at line 1086 of file util.c.

Referenced by ruby_strtod().

#define Bletch 0x10

Definition at line 978 of file util.c.

Referenced by ruby_dtoa().

#define Bndry_mask 0xfffff

Definition at line 979 of file util.c.

Referenced by ruby_dtoa(), and ruby_strtod().

#define Bndry_mask1 0xfffff

Definition at line 980 of file util.c.

Referenced by ruby_strtod().

#define C ((int*)c)

Definition at line 370 of file util.c.

Referenced by mmrot3_(), and vm_init_redefined_flag().

#define D ((int*)d)

Definition at line 371 of file util.c.

Referenced by permute().

#define d0 word0(d)

Referenced by b2d(), d2b(), math_acos(), math_acosh(), math_asin(), math_atanh(), math_gamma(), math_lgamma(), math_log(), math_log10(), math_log2(), and math_sqrt().

#define d0 word0(d)

#define d1 word1(d)

Referenced by b2d(), d2b(), and inet_pton().

#define d1 word1(d)

#define DBL_ADJ (DBL_MAX_EXP - 2)

Definition at line 3932 of file util.c.

Referenced by ruby_hdtoa().

#define DBL_MANH_SIZE 20

Definition at line 3930 of file util.c.

Referenced by ruby_hdtoa().

#define DBL_MANL_SIZE 32

Definition at line 3931 of file util.c.

Referenced by ruby_hdtoa().

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

Definition at line 3934 of file util.c.

Referenced by ruby_hdtoa().

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

Definition at line 3935 of file util.c.

Referenced by ruby_hdtoa().

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

Definition at line 3936 of file util.c.

Referenced by ruby_hdtoa().

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

Definition at line 3937 of file util.c.

Referenced by ruby_hdtoa().

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

Definition at line 942 of file util.c.

Referenced by b2d(), d2b(), ratio(), ruby_dtoa(), ruby_strtod(), and ulp().

#define Ebits 11

Definition at line 974 of file util.c.

Referenced by b2d().

#define Emin (-1022)

Definition at line 971 of file util.c.

Referenced by ruby_strtod().

#define Exp_1 0x3ff00000

Definition at line 972 of file util.c.

Referenced by b2d(), ruby_dtoa(), and ruby_strtod().

#define Exp_11 0x3ff00000

Definition at line 973 of file util.c.

Referenced by ruby_dtoa().

#define Exp_mask 0x7ff00000

Definition at line 968 of file util.c.

Referenced by ruby_dtoa(), ruby_strtod(), and ulp().

#define Exp_msk1 0x100000

Definition at line 966 of file util.c.

Referenced by d2b(), ratio(), ruby_dtoa(), ruby_strtod(), and ulp().

#define Exp_msk11 0x100000

Definition at line 967 of file util.c.

Referenced by d2b().

#define Exp_shift 20

Definition at line 964 of file util.c.

Referenced by d2b(), ruby_dtoa(), ruby_strtod(), and ulp().

#define Exp_shift1 20

Definition at line 965 of file util.c.

Referenced by ruby_dtoa().

#define FFFFFFFF 0xffffffffUL

Definition at line 1092 of file util.c.

Referenced by diff(), mult(), multadd(), and quorem().

#define Flt_Rounds 1

Definition at line 999 of file util.c.

Referenced by ruby_dtoa(), and ruby_strtod().

#define Frac_mask 0xfffff

Definition at line 975 of file util.c.

Referenced by d2b(), ruby_dtoa(), and ruby_strtod().

#define Frac_mask1 0xfffff

Definition at line 976 of file util.c.

Referenced by ruby_dtoa().

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

Definition at line 1120 of file util.c.

Referenced by Balloc(), Bfree(), and pow5mult().

#define IEEE_Arith

Definition at line 870 of file util.c.

Referenced by ruby_strtod().

#define IEEE_LITTLE_ENDIAN

Definition at line 809 of file util.c.

#define Int_max 14

Definition at line 987 of file util.c.

Referenced by ruby_dtoa().

#define Kmax 15

Definition at line 1123 of file util.c.

#define Llong long long

Definition at line 1106 of file util.c.

#define Log2P 1

Definition at line 983 of file util.c.

Referenced by ruby_dtoa(), and ruby_strtod().

#define LSB 1

Definition at line 981 of file util.c.

Referenced by ruby_strtod().

#define MALLOC malloc

Definition at line 853 of file util.c.

Referenced by Balloc().

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

Value:
((*cmp)((a),(b),d)<0 ? \
((*cmp)((b),(c),d)<0 ? (b) : ((*cmp)((a),(c),d)<0 ? (c) : (a))) : \
((*cmp)((b),(c),d)>0 ? (b) : ((*cmp)((a),(c),d)<0 ? (a) : (c))))

Definition at line 446 of file util.c.

Referenced by ruby_qsort().

#define mmarg mmkind, size, high, low

Definition at line 382 of file util.c.

#define mmprepare | ( |  | base,
|  |  | size
| ) |  |

Value:
do {\
if (((VALUE)(base) & (0x3)) == 0)\
if ((size) >= 16) mmkind = 1;\
else mmkind = 0;\
else mmkind = -1;\
high = ((size) & (~0xf));\
low = ((size) & 0x0c);\
} while (0)\

Definition at line 373 of file util.c.

Referenced by ruby_qsort().

#define mmrot3 | ( |  | a,
|  |  | b,
|  |  | c
| ) |  | mmrot3_((a),(b),(c),mmarg)

Definition at line 431 of file util.c.

Referenced by ruby_qsort().

#define mmswap | ( |  | a,
|  |  | b
| ) |  | mmswap_((a),(b),mmarg)

Definition at line 407 of file util.c.

Referenced by ruby_qsort().

#define MULTIPLE_THREADS 1

Definition at line 1113 of file util.c.

#define n_bigtens 5

Definition at line 1976 of file util.c.

Referenced by ruby_dtoa(), and ruby_strtod().

#define P 53

Definition at line 969 of file util.c.

Referenced by d2b(), ruby_dtoa(), ruby_strtod(), and ulp().

#define Pack_32

Definition at line 1089 of file util.c.

#define PATH_MAX 8192

Referenced by ruby_getcwd().

#define POP | ( |  | ll,
|  |  | rr
| ) |  | do { --top; (ll) = top->LL; (rr) = top->RR; } while (0) /* Pop L,l,R,r */

Definition at line 444 of file util.c.

Referenced by ruby_qsort().

#define PRIVATE_MEM 2304

Definition at line 858 of file util.c.

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

Definition at line 860 of file util.c.

Referenced by Balloc().

#define PUSH | ( |  | ll,
|  |  | rr
| ) |  | do { top->LL = (ll); top->RR = (rr); ++top; } while (0) /* Push L,l,R,r */

Definition at line 443 of file util.c.

Referenced by ruby_qsort().

#define Quick_max 14

Definition at line 986 of file util.c.

Referenced by ruby_dtoa().

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

Definition at line 1081 of file util.c.

Referenced by ruby_strtod().

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

Definition at line 1082 of file util.c.

Referenced by ruby_strtod().

#define Rounding Flt_Rounds

Definition at line 1008 of file util.c.

Referenced by ruby_dtoa(), and ruby_strtod().

#define rv_alloc | ( |  | i | ) | xmalloc(i)

Definition at line 3145 of file util.c.

Referenced by nrv_alloc(), ruby_dtoa(), and ruby_hdtoa().

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

Definition at line 3160 of file util.c.

Referenced by ruby_dtoa(), and ruby_hdtoa().

#define S_ISDIR | ( |  | m | ) | (((m) & S_IFMT) == S_IFDIR)

Definition at line 184 of file util.c.

#define Scale_Bit 0x10

Definition at line 1975 of file util.c.

Referenced by ruby_strtod().

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

Definition at line 3933 of file util.c.

Referenced by ruby_hdtoa().

#define Sign_bit 0x80000000

Definition at line 982 of file util.c.

Referenced by ruby_dtoa(), and ruby_hdtoa().

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

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

Definition at line 950 of file util.c.

Referenced by diff(), mult(), and quorem().

#define Ten_pmax 22

Definition at line 977 of file util.c.

Referenced by ruby_dtoa(), and ruby_strtod().

#define Tiny0 0

Definition at line 984 of file util.c.

Referenced by ruby_strtod().

#define Tiny1 1

Definition at line 985 of file util.c.

Referenced by ruby_strtod().

#define ULLong unsigned Llong

Definition at line 1109 of file util.c.

Referenced by diff(), mult(), multadd(), and quorem().

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

Definition at line 936 of file util.c.

Referenced by b2d(), d2b(), ratio(), ruby_dtoa(), ruby_hdtoa(), ruby_strtod(), and ulp().

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

Definition at line 937 of file util.c.

Referenced by b2d(), d2b(), ruby_dtoa(), ruby_strtod(), and ulp().

## Typedef Documentation

typedef struct Bigint Bigint

Definition at line 1131 of file util.c.

typedef U double_u

Definition at line 934 of file util.c.

## Function Documentation

static double b2d | ( | Bigint * | a,
|  | int * | e
| ) |  |

static

Definition at line 1715 of file util.c.

References d0, d1, dval, Ebits, Exp_1, hi0bits(), Bigint::k, Bigint::wds, word0, word1, and Bigint::x.

Referenced by ratio().

static Bigint* Balloc | ( | int | k | ) |

static

Definition at line 1136 of file util.c.

References ACQUIRE_DTOA_LOCK, FREE_DTOA_LOCK, Bigint::k, len, MALLOC, Bigint::maxwds, Bigint::next, PRIVATE_mem, Bigint::sign, Bigint::wds, and Bigint::x.

Referenced by d2b(), diff(), i2b(), lshift(), mult(), multadd(), ruby_dtoa(), ruby_strtod(), and s2b().

static void Bfree | ( | Bigint * | v | ) |

static

Definition at line 1171 of file util.c.

References ACQUIRE_DTOA_LOCK, FREE_DTOA_LOCK, Bigint::k, Bigint::next, and v.

Referenced by lshift(), multadd(), pow5mult(), ruby_dtoa(), and ruby_strtod().

static int cmp | ( | Bigint * | a,
|  | Bigint * | b
| ) |  |

static

Definition at line 1562 of file util.c.

References i, Bigint::wds, and Bigint::x.

Referenced by diff(), quorem(), ruby_dtoa(), ruby_qsort(), and ruby_strtod().

static Bigint* d2b | ( | double | d_,
|  | int * | e,
|  | int * | bits
| ) |  |

static

Definition at line 1780 of file util.c.

References Balloc(), Bias, d0, d1, dval, Exp_msk1, Exp_msk11, Exp_shift, Frac_mask, hi0bits(), i, Bigint::k, lo0bits(), P, Bigint::wds, word0, word1, and Bigint::x.

Referenced by ruby_dtoa(), and ruby_strtod().

static Bigint* diff | ( | Bigint * | a,
|  | Bigint * | b
| ) |  |

static

Definition at line 1591 of file util.c.

References Balloc(), cmp(), FFFFFFFF, i, Bigint::k, Bigint::sign, Storeinc, ULLong, Bigint::wds, and Bigint::x.

Referenced by fun_sio_from_gb18030(), fun_sio_to_gb18030(), num_step(), pair_byte_cmp(), rb_dlptr_cmp(), ruby_dtoa(), and ruby_strtod().

static int hi0bits | ( | register ULong | x | ) |

static

Definition at line 1270 of file util.c.

References Bigint::k.

Referenced by b2d(), d2b(), and ruby_dtoa().

static Bigint* i2b | ( | int | i | ) |

static

Definition at line 1342 of file util.c.

References Balloc(), i, Bigint::wds, and Bigint::x.

Referenced by pow5mult(), ruby_dtoa(), and ruby_strtod().

static int lo0bits | ( | ULong * | y | ) |

static

Definition at line 1299 of file util.c.

References Bigint::k, and Bigint::x.

Referenced by d2b().

static Bigint* lshift | ( | Bigint * | b,
|  | int | k
| ) |  |

static

Definition at line 1508 of file util.c.

References Balloc(), Bfree(), i, Bigint::k, Bigint::maxwds, Bigint::wds, and Bigint::x.

Referenced by ruby_dtoa(), and ruby_strtod().

static void mmrot3_ | ( | register char * | a,
|  | register char * | b,
|  | register char * | c,
|  | int | mmkind,
|  | size_t | size,
|  | size_t | high,
|  | size_t | low
| ) |  |

static

Definition at line 409 of file util.c.

References A, B, C, and size.

static void mmswap_ | ( | register char * | a,
|  | register char * | b,
|  | int | mmkind,
|  | size_t | size,
|  | size_t | high,
|  | size_t | low
| ) |  |

static

Definition at line 384 of file util.c.

References A, B, and size.

static Bigint* mult | ( | Bigint * | a,
|  | Bigint * | b
| ) |  |

static

Definition at line 1353 of file util.c.

References Balloc(), FFFFFFFF, Bigint::k, Bigint::maxwds, Storeinc, ULLong, Bigint::wds, and Bigint::x.

Referenced by pow5mult(), ruby_dtoa(), and ruby_strtod().

static Bigint* multadd | ( | Bigint * | b,
|  | int | m,
|  | int | a
| ) |  |

static

Definition at line 1185 of file util.c.

References Balloc(), Bcopy, Bfree(), FFFFFFFF, i, Bigint::k, Bigint::maxwds, ULLong, Bigint::wds, and Bigint::x.

Referenced by pow5mult(), ruby_dtoa(), and s2b().

static char* nrv_alloc | ( | const char * | s,
|  | char ** | rve,
|  | size_t | n
| ) |  |

static

Definition at line 3149 of file util.c.

References rv_alloc.

static Bigint* pow5mult | ( | Bigint * | b,
|  | int | k
| ) |  |

static

Definition at line 1456 of file util.c.

References ACQUIRE_DTOA_LOCK, Bfree(), FREE_DTOA_LOCK, i, i2b(), mult(), multadd(), and Bigint::next.

Referenced by ruby_dtoa(), and ruby_strtod().

static int quorem | ( | Bigint * | b,
|  | Bigint * | S
| ) |  |

static

Definition at line 3024 of file util.c.

References cmp(), FFFFFFFF, Storeinc, ULLong, Bigint::wds, and Bigint::x.

Referenced by ruby_dtoa().

static double ratio | ( | Bigint * | a,
|  | Bigint * | b
| ) |  |

static

Definition at line 1917 of file util.c.

References b2d(), dval, Exp_msk1, Bigint::k, Bigint::wds, and word0.

Referenced by ruby_strtod().

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

Definition at line 3215 of file util.c.

References Balloc(), Bcopy, Bfree(), Bias, bigtens, Bletch, Bndry_mask, cmp(), d2b(), diff(), dval, Exp_1, Exp_11, Exp_mask, Exp_msk1, Exp_shift, Exp_shift1, Flt_Rounds, Frac_mask, Frac_mask1, hi0bits(), i, i2b(), Int_max, Bigint::k, Log2P, lshift(), mult(), multadd(), n_bigtens, no_digits, P, pow5mult(), Quick_max, quorem(), Rounding, rv_alloc, rv_strdup, S, Bigint::sign, Sign_bit, Ten_pmax, tens, Bigint::wds, word0, word1, and Bigint::x.

Referenced by flo_to_s(), and w_float().

void ruby_each_words | ( | const char * | str,
|  | void(*)(const char *, int, void *) | func,
|  | void * | arg
| ) |  |

Definition at line 3888 of file util.c.

References arg, ISSPACE, and len.

char* ruby_getcwd | ( | void |  | ) |

Definition at line 613 of file util.c.

References buf, errno, PATH_MAX, rb_sys_fail(), xfree(), xmalloc, and xrealloc.

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

Definition at line 3965 of file util.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, Sign_bit, and word0.

void ruby_qsort | ( | void * | base,
|  | const size_t | nel,
|  | const size_t | size,
|  | int(*)(const void *, const void *, void *) | cmp,
|  | void * | d
| ) |  |

Definition at line 451 of file util.c.

References cmp(), fail, med3, mmprepare, mmrot3, mmswap, p, POP, PUSH, R, size, and top.

unsigned long ruby_scan_hex | ( | const char * | start,
|  | size_t | len,
|  | size_t * | retlen
| ) |  |

Definition at line 42 of file util.c.

References strchr().

unsigned long ruby_scan_oct | ( | const char * | start,
|  | size_t | len,
|  | size_t * | retlen
| ) |  |

Definition at line 28 of file util.c.

char* ruby_strdup | ( | const char * | str | ) |

Definition at line 601 of file util.c.

References strlen(), and xmalloc.

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

Definition at line 2070 of file util.c.

References Avoid_Underflow, Balloc(), Bcopy, Bfree(), Bias, Big0, Big1, bigtens, Bndry_mask, Bndry_mask1, cmp(), d2b(), DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP, diff(), dval, Emin, errno, Exp_1, Exp_mask, Exp_msk1, Exp_shift, FLT_RADIX, Flt_Rounds, Frac_mask, i, i2b(), IEEE_Arith, ISDIGIT, Bigint::k, Log2P, LSB, lshift(), match(), mult(), n_bigtens, NULL, P, pow5mult(), ratio(), rounded_product, rounded_quotient, Rounding, s2b(), Scale_Bit, Bigint::sign, strchr(), Ten_pmax, tens, Tiny0, Tiny1, ulp(), Bigint::wds, word0, word1, and Bigint::x.

unsigned long ruby_strtoul | ( | const char * | str,
|  | char ** | endptr,
|  | int | base
| ) |  |

Definition at line 106 of file util.c.

References errno, ISSPACE, len, long, and scan_digits().

static Bigint* s2b | ( | const char * | s,
|  | int | nd0,
|  | int | nd,
|  | ULong | y9
| ) |  |

static

Definition at line 1236 of file util.c.

References Balloc(), i, Bigint::k, multadd(), Bigint::wds, and Bigint::x.

Referenced by ruby_strtod().

static unsigned long scan_digits | ( | const char * | str,
|  | int | base,
|  | size_t * | retlen,
|  | int * | overflow
| ) |  |

static

Definition at line 59 of file util.c.

References long.

Referenced by ruby_strtoul().

static double ulp | ( | double | x_ | ) |

static

Definition at line 1677 of file util.c.

References dval, Exp_mask, Exp_msk1, Exp_shift, P, word0, word1, and Bigint::x.

Referenced by ruby_strtod().

## Variable Documentation

const double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }

static

Definition at line 1964 of file util.c.

Referenced by ruby_dtoa(), and ruby_strtod().

Bigint* freelist[Kmax+1]

static

Definition at line 1133 of file util.c.

const char INFSTR[] = "Infinity"

static

Definition at line 3176 of file util.c.

const char NANSTR[] = "NaN"

static

Definition at line 3177 of file util.c.

Bigint* p5s

static

Definition at line 1453 of file util.c.

double * pmem_next = private_mem

static

Definition at line 861 of file util.c.

double private_mem[PRIVATE_mem]

static

Definition at line 861 of file util.c.

const double tens[]

static

Initial value:
= {
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
1e20, 1e21, 1e22
}

Definition at line 1953 of file util.c.

Referenced by ruby_dtoa(), and ruby_strtod().

const double tinytens[]

static

Initial value:
= { 1e-16, 1e-32, 1e-64, 1e-128,
9007199254740992.*9007199254740992.e-256
}

Definition at line 1965 of file util.c.

const char ZEROSTR[] = "0"

static

Definition at line 3178 of file util.c.