#include "OSConfig.h"
#include "OSdtoa.h"
#include "stdlib.h"
#include "string.h"
#include "errno.h"
#include "float.h"
#include "math.h"
Go to the source code of this file.
Classes | |
union | U |
struct | Bigint |
Defines | |
#define | IEEE_8087 |
the following is OS code put bigendian check here | |
#define | INFNAN_CHECK |
#define | NO_LONG_LONG |
#define | Just_16 |
#define | Long int |
#define | Intcast (int)(long) |
#define | MALLOC malloc |
#define | PRIVATE_MEM 2304 |
#define | PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double)) |
#define | IEEE_Arith |
#define | INFNAN_CHECK |
#define | CONST const |
#define | word0(x) ((U*)&x)->L[1] |
#define | word1(x) ((U*)&x)->L[0] |
#define | dval(x) ((U*)&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 | FFFFFFFF 0xffffffffUL |
#define | ACQUIRE_DTOA_LOCK(n) |
#define | FREE_DTOA_LOCK(n) |
#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 | NAN_WORD0 0x7ff80000 |
#define | NAN_WORD1 0 |
Typedefs | |
typedef unsigned Long | ULong |
end of OS code, below is David Gay except we changed the names of dtoa to os_dtoa strtod to os-strtod and freedtoa to os_freedtoa | |
typedef struct Bigint | Bigint |
Functions | |
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) |
static int | match (CONST char **sp, char *t) |
static void | hexnan (double *rvp, CONST char **sp) |
double | os_strtod (CONST char *s00, char **se) |
static int | quorem (Bigint *b, Bigint *S) |
static char * | rv_alloc (int i) |
static char * | nrv_alloc (char *s, char **rve, int n) |
void | os_freedtoa (char *s) |
char * | os_dtoa (double d, int mode, 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 char * | dtoa_result |
#define IEEE_8087 |
#define INFNAN_CHECK |
Definition at line 266 of file OSdtoa.cpp.
#define NO_LONG_LONG |
Definition at line 189 of file OSdtoa.cpp.
#define Just_16 |
Definition at line 190 of file OSdtoa.cpp.
#define Long int |
#define Intcast (int)(long) |
#define MALLOC malloc |
#define PRIVATE_MEM 2304 |
Definition at line 248 of file OSdtoa.cpp.
#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double)) |
#define IEEE_Arith |
#define INFNAN_CHECK |
Definition at line 266 of file OSdtoa.cpp.
#define CONST const |
#define word0 | ( | x | ) | ((U*)&x)->L[1] |
Definition at line 340 of file OSdtoa.cpp.
Referenced by b2d(), d2b(), hexnan(), os_dtoa(), os_strtod(), ratio(), and ulp().
#define word1 | ( | x | ) | ((U*)&x)->L[0] |
Definition at line 341 of file OSdtoa.cpp.
Referenced by b2d(), d2b(), hexnan(), os_dtoa(), os_strtod(), and ulp().
#define dval | ( | x | ) | ((U*)&x)->d |
Definition at line 346 of file OSdtoa.cpp.
Referenced by b2d(), os_dtoa(), os_strtod(), ratio(), and ulp().
#define Storeinc | ( | a, | |||
b, | |||||
c | ) |
Value:
(((unsigned short *)a)[1] = (unsigned short)b, \ ((unsigned short *)a)[0] = (unsigned short)c, a++)
Definition at line 354 of file OSdtoa.cpp.
#define Exp_shift 20 |
#define Exp_shift1 20 |
#define Exp_msk1 0x100000 |
Definition at line 370 of file OSdtoa.cpp.
Referenced by d2b(), os_dtoa(), os_strtod(), ratio(), and ulp().
#define Exp_msk11 0x100000 |
#define Exp_mask 0x7ff00000 |
Definition at line 372 of file OSdtoa.cpp.
Referenced by hexnan(), os_dtoa(), os_strtod(), and ulp().
#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 FFFFFFFF 0xffffffffUL |
#define ACQUIRE_DTOA_LOCK | ( | n | ) |
#define FREE_DTOA_LOCK | ( | n | ) |
#define Kmax 15 |
Definition at line 530 of file OSdtoa.cpp.
#define Bcopy | ( | x, | |||
y | ) |
Value:
memcpy((char *)&x->sign, (char *)&y->sign, \ y->wds*sizeof(Long) + 2*sizeof(int))
Definition at line 605 of file OSdtoa.cpp.
Referenced by multadd(), os_dtoa(), and os_strtod().
#define d0 word0(d) |
#define d1 word1(d) |
#define Scale_Bit 0x10 |
#define n_bigtens 5 |
#define NAN_WORD0 0x7ff80000 |
#define NAN_WORD1 0 |
typedef unsigned Long ULong |
end of OS code, below is David Gay except we changed the names of dtoa to os_dtoa strtod to os-strtod and freedtoa to os_freedtoa
Definition at line 221 of file OSdtoa.cpp.
Definition at line 545 of file OSdtoa.cpp.
static Bigint* Balloc | ( | int | k | ) | [static] |
Definition at line 554 of file OSdtoa.cpp.
References ACQUIRE_DTOA_LOCK, FREE_DTOA_LOCK, Bigint::k, MALLOC, Bigint::maxwds, Bigint::next, pmem_next, PRIVATE_mem, private_mem, Bigint::sign, Bigint::wds, and Bigint::x.
Referenced by d2b(), diff(), i2b(), lshift(), mult(), multadd(), os_dtoa(), os_strtod(), rv_alloc(), and s2b().
static void Bfree | ( | Bigint * | v | ) | [static] |
Definition at line 594 of file OSdtoa.cpp.
References ACQUIRE_DTOA_LOCK, and FREE_DTOA_LOCK.
Referenced by lshift(), multadd(), os_dtoa(), os_freedtoa(), os_strtod(), and pow5mult().
Definition at line 613 of file OSdtoa.cpp.
References Balloc(), Bcopy, Bfree(), FFFFFFFF, Bigint::k, Bigint::maxwds, Bigint::wds, and Bigint::x.
Referenced by os_dtoa(), pow5mult(), and s2b().
Definition at line 670 of file OSdtoa.cpp.
References Balloc(), Bigint::k, Long, multadd(), Bigint::wds, and Bigint::x.
Referenced by os_strtod().
static int hi0bits | ( | register ULong | x | ) | [static] |
static int lo0bits | ( | ULong * | y | ) | [static] |
Definition at line 742 of file OSdtoa.cpp.
References Bigint::k, and Bigint::x.
Referenced by d2b().
static Bigint* i2b | ( | int | i | ) | [static] |
Definition at line 790 of file OSdtoa.cpp.
References Balloc(), Bigint::wds, and Bigint::x.
Referenced by os_dtoa(), os_strtod(), and pow5mult().
Definition at line 806 of file OSdtoa.cpp.
References Balloc(), FFFFFFFF, Bigint::k, Bigint::maxwds, Storeinc, Bigint::wds, and Bigint::x.
Referenced by os_dtoa(), os_strtod(), and pow5mult().
Definition at line 918 of file OSdtoa.cpp.
References ACQUIRE_DTOA_LOCK, Bfree(), FREE_DTOA_LOCK, i2b(), mult(), multadd(), and Bigint::next.
Referenced by os_dtoa(), and os_strtod().
Definition at line 975 of file OSdtoa.cpp.
References Balloc(), Bfree(), Bigint::k, Bigint::maxwds, Bigint::wds, and Bigint::x.
Referenced by os_dtoa(), and os_strtod().
Definition at line 1035 of file OSdtoa.cpp.
References Bigint::wds, and Bigint::x.
Referenced by diff(), os_dtoa(), os_strtod(), and quorem().
Definition at line 1069 of file OSdtoa.cpp.
References Balloc(), cmp(), FFFFFFFF, Bigint::k, Bigint::sign, Storeinc, Bigint::wds, and Bigint::x.
Referenced by os_dtoa(), and os_strtod().
static double ulp | ( | double | x | ) | [static] |
static double b2d | ( | Bigint * | a, | |
int * | e | |||
) | [static] |
static Bigint* d2b | ( | double | d, | |
int * | e, | |||
int * | bits | |||
) | [static] |
Definition at line 1413 of file OSdtoa.cpp.
References b2d(), dval, Exp_msk1, Bigint::wds, and word0.
Referenced by os_strtod().
static int match | ( | CONST char ** | sp, | |
char * | t | |||
) | [static] |
static void hexnan | ( | double * | rvp, | |
CONST char ** | sp | |||
) | [static] |
Definition at line 1523 of file OSdtoa.cpp.
References CONST, Exp_mask, word0, word1, and Bigint::x.
Referenced by os_strtod().
double os_strtod | ( | CONST char * | s00, | |
char ** | se | |||
) |
Definition at line 1577 of file OSdtoa.cpp.
References Avoid_Underflow, Balloc(), Bcopy, Bfree(), Bias, Big0, Big1, bigtens, Bndry_mask, Bndry_mask1, cmp(), CONST, d2b(), diff(), dval, Emin, Exp_1, Exp_mask, Exp_msk1, Exp_shift, Flt_Rounds, Frac_mask, hexnan(), i2b(), IEEE_Arith, Log2P, Long, LSB, lshift(), match(), mult(), n_bigtens, NAN_WORD0, NAN_WORD1, P, pow5mult(), ratio(), rounded_product, rounded_quotient, Rounding, s2b(), Scale_Bit, Bigint::sign, Ten_pmax, tens, Tiny0, Tiny1, ulp(), word0, and word1.
Referenced by getObjVal(), and os_strtod_wrap().
Definition at line 2468 of file OSdtoa.cpp.
References cmp(), FFFFFFFF, Storeinc, Bigint::wds, and Bigint::x.
Referenced by os_dtoa().
static char* rv_alloc | ( | int | i | ) | [static] |
Definition at line 2589 of file OSdtoa.cpp.
References Balloc().
Referenced by nrv_alloc(), and os_dtoa().
static char* nrv_alloc | ( | char * | s, | |
char ** | rve, | |||
int | n | |||
) | [static] |
void os_freedtoa | ( | char * | s | ) |
Definition at line 2634 of file OSdtoa.cpp.
References Bfree(), Bigint::k, and Bigint::maxwds.
Referenced by os_dtoa(), and os_dtoa_format().
char* os_dtoa | ( | double | d, | |
int | mode, | |||
int | ndigits, | |||
int * | decpt, | |||
int * | sign, | |||
char ** | rve | |||
) |
Definition at line 2686 of file OSdtoa.cpp.
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(), i2b(), Int_max, Log2P, Long, lshift(), mult(), multadd(), n_bigtens, nrv_alloc(), os_freedtoa(), P, pow5mult(), Quick_max, quorem(), Rounding, rv_alloc(), Bigint::sign, Sign_bit, Ten_pmax, tens, Bigint::wds, word0, word1, and Bigint::x.
Referenced by os_dtoa_format().
double private_mem[PRIVATE_mem] [static] |
double * pmem_next = private_mem [static] |
Definition at line 547 of file OSdtoa.cpp.
Definition at line 911 of file OSdtoa.cpp.
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 1450 of file OSdtoa.cpp.
Referenced by os_dtoa(), and os_strtod().
CONST double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 } [static] |
CONST double tinytens[] [static] |
Initial value:
{ 1e-16, 1e-32, 1e-64, 1e-128, 9007199254740992.*9007199254740992.e-256 }
Definition at line 1462 of file OSdtoa.cpp.
char* dtoa_result [static] |
Definition at line 2582 of file OSdtoa.cpp.