My Project
OSdtoa.cpp File Reference
#include "OSConfig.h"
#include "OSdtoa.h"
#include "OSParameters.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  BCinfo
 
struct  Bigint
 

Macros

#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)   (x)->L[1]
 
#define word1(x)   (x)->L[0]
 
#define dval(x)   (x)->d
 
#define STRTOD_DIGLIM   40
 
#define strtod_diglim   STRTOD_DIGLIM
 
#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 Nbits   53
 
#define Bias   1023
 
#define Emax   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 ACQUIRE_DTOA_LOCK(n)   /*nothing*/
 
#define FREE_DTOA_LOCK(n)   /*nothing*/
 
#define Kmax   7
 
#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 Need_Hexdig
 
#define NAN_WORD0   0x7ff80000
 
#define NAN_WORD1   0
 
#define ULbits   16
 
#define kshift   4
 
#define kmask   15
 

Typedefs

typedef unsigned Long ULong
 end of OS code, below is David Gay, except as noted above
 
typedef struct BCinfo BCinfo
 
typedef struct Bigint Bigint
 

Enumerations

enum  { Round_zero = 0 , Round_near = 1 , Round_up = 2 , Round_down = 3 }
 

Functions

static BigintBalloc (int k)
 
static void Bfree (Bigint *v)
 
static Bigintmultadd (Bigint *b, int m, int a)
 
static Bigints2b (const char *s, int nd0, int nd, ULong y9, int dplen)
 
static int hi0bits (ULong x)
 
static int lo0bits (ULong *y)
 
static Biginti2b (int i)
 
static Bigintmult (Bigint *a, Bigint *b)
 
static Bigintpow5mult (Bigint *b, int k)
 
static Bigintlshift (Bigint *b, int k)
 
static int cmp (Bigint *a, Bigint *b)
 
static Bigintdiff (Bigint *a, Bigint *b)
 
static double ulp (U *x)
 
static double b2d (Bigint *a, int *e)
 
static Bigintd2b (U *d, int *e, int *bits)
 
static double ratio (Bigint *a, Bigint *b)
 
static int match (const char **sp, const char *t)
 
static void hexnan (U *rvp, const char **sp)
 
static Bigintincrement (Bigint *b)
 
static void rshift (Bigint *b, int k)
 
static ULong any_on (Bigint *b, int k)
 
void os_gethex (CONST char **sp, U *rvp, int rounding, int sign)
 
static int dshift (Bigint *b, int p2)
 
static int quorem (Bigint *b, Bigint *S)
 
static double sulp (U *x, BCinfo *bc)
 
static void bigcomp (U *rv, const char *s0, BCinfo *bc)
 
double os_strtod (const char *s00, char **se)
 
static char * rv_alloc (int i)
 
static char * nrv_alloc (const char *s, char **rve, int n)
 
void os_freedtoa (char *s)
 
char * os_dtoa (double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
 

Variables

static double private_mem [PRIVATE_mem]
 
static double * pmem_next = private_mem
 
static Bigintfreelist [Kmax+1]
 
static Bigintp5s
 
static CONST double tens []
 
static CONST double bigtens [] = { 1e16, 1e32, 1e64, 1e128, 1e256 }
 
static CONST double tinytens []
 
static unsigned char hexdig [256]
 
static char * dtoa_result
 

Macro Definition Documentation

◆ IEEE_8087

#define IEEE_8087

the following is OS code put bigendian check here

Definition at line 28 of file OSdtoa.cpp.

◆ INFNAN_CHECK [1/2]

#define INFNAN_CHECK

Definition at line 31 of file OSdtoa.cpp.

◆ NO_LONG_LONG

#define NO_LONG_LONG

Definition at line 33 of file OSdtoa.cpp.

◆ Just_16

#define Just_16

Definition at line 34 of file OSdtoa.cpp.

◆ Long

#define Long   int

Definition at line 37 of file OSdtoa.cpp.

◆ Intcast

#define Intcast   (int)(long)

Definition at line 38 of file OSdtoa.cpp.

◆ MALLOC

#define MALLOC   malloc

Definition at line 269 of file OSdtoa.cpp.

◆ PRIVATE_MEM

#define PRIVATE_MEM   2304

Definition at line 274 of file OSdtoa.cpp.

◆ PRIVATE_mem

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

Definition at line 276 of file OSdtoa.cpp.

◆ IEEE_Arith

#define IEEE_Arith

Definition at line 286 of file OSdtoa.cpp.

◆ INFNAN_CHECK [2/2]

#define INFNAN_CHECK

Definition at line 31 of file OSdtoa.cpp.

◆ CONST

#define CONST   const

Definition at line 346 of file OSdtoa.cpp.

◆ word0

#define word0 ( x)    (x)->L[1]

Definition at line 357 of file OSdtoa.cpp.

◆ word1

#define word1 ( x)    (x)->L[0]

Definition at line 358 of file OSdtoa.cpp.

◆ dval

#define dval ( x)    (x)->d

Definition at line 363 of file OSdtoa.cpp.

◆ STRTOD_DIGLIM

#define STRTOD_DIGLIM   40

Definition at line 366 of file OSdtoa.cpp.

◆ strtod_diglim

#define strtod_diglim   STRTOD_DIGLIM

Definition at line 372 of file OSdtoa.cpp.

◆ 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 380 of file OSdtoa.cpp.

◆ Exp_shift

#define Exp_shift   20

Definition at line 394 of file OSdtoa.cpp.

◆ Exp_shift1

#define Exp_shift1   20

Definition at line 395 of file OSdtoa.cpp.

◆ Exp_msk1

#define Exp_msk1   0x100000

Definition at line 396 of file OSdtoa.cpp.

◆ Exp_msk11

#define Exp_msk11   0x100000

Definition at line 397 of file OSdtoa.cpp.

◆ Exp_mask

#define Exp_mask   0x7ff00000

Definition at line 398 of file OSdtoa.cpp.

◆ P

#define P   53

Definition at line 399 of file OSdtoa.cpp.

◆ Nbits

#define Nbits   53

Definition at line 400 of file OSdtoa.cpp.

◆ Bias

#define Bias   1023

Definition at line 401 of file OSdtoa.cpp.

◆ Emax

#define Emax   1023

Definition at line 402 of file OSdtoa.cpp.

◆ Emin

#define Emin   (-1022)

Definition at line 403 of file OSdtoa.cpp.

◆ Exp_1

#define Exp_1   0x3ff00000

Definition at line 404 of file OSdtoa.cpp.

◆ Exp_11

#define Exp_11   0x3ff00000

Definition at line 405 of file OSdtoa.cpp.

◆ Ebits

#define Ebits   11

Definition at line 406 of file OSdtoa.cpp.

◆ Frac_mask

#define Frac_mask   0xfffff

Definition at line 407 of file OSdtoa.cpp.

◆ Frac_mask1

#define Frac_mask1   0xfffff

Definition at line 408 of file OSdtoa.cpp.

◆ Ten_pmax

#define Ten_pmax   22

Definition at line 409 of file OSdtoa.cpp.

◆ Bletch

#define Bletch   0x10

Definition at line 410 of file OSdtoa.cpp.

◆ Bndry_mask

#define Bndry_mask   0xfffff

Definition at line 411 of file OSdtoa.cpp.

◆ Bndry_mask1

#define Bndry_mask1   0xfffff

Definition at line 412 of file OSdtoa.cpp.

◆ LSB

#define LSB   1

Definition at line 413 of file OSdtoa.cpp.

◆ Sign_bit

#define Sign_bit   0x80000000

Definition at line 414 of file OSdtoa.cpp.

◆ Log2P

#define Log2P   1

Definition at line 415 of file OSdtoa.cpp.

◆ Tiny0

#define Tiny0   0

Definition at line 416 of file OSdtoa.cpp.

◆ Tiny1

#define Tiny1   1

Definition at line 417 of file OSdtoa.cpp.

◆ Quick_max

#define Quick_max   14

Definition at line 418 of file OSdtoa.cpp.

◆ Int_max

#define Int_max   14

Definition at line 419 of file OSdtoa.cpp.

◆ Avoid_Underflow

#define Avoid_Underflow

Definition at line 421 of file OSdtoa.cpp.

◆ Flt_Rounds

#define Flt_Rounds   1

Definition at line 431 of file OSdtoa.cpp.

◆ Rounding

#define Rounding   Flt_Rounds

Definition at line 439 of file OSdtoa.cpp.

◆ rounded_product

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

Definition at line 527 of file OSdtoa.cpp.

◆ rounded_quotient

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

Definition at line 528 of file OSdtoa.cpp.

◆ Big0

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

Definition at line 531 of file OSdtoa.cpp.

◆ Big1

#define Big1   0xffffffff

Definition at line 532 of file OSdtoa.cpp.

◆ Pack_32

#define Pack_32

Definition at line 535 of file OSdtoa.cpp.

◆ FFFFFFFF

#define FFFFFFFF   0xffffffffUL

Definition at line 545 of file OSdtoa.cpp.

◆ ACQUIRE_DTOA_LOCK

#define ACQUIRE_DTOA_LOCK ( n)    /*nothing*/

Definition at line 568 of file OSdtoa.cpp.

◆ FREE_DTOA_LOCK

#define FREE_DTOA_LOCK ( n)    /*nothing*/

Definition at line 569 of file OSdtoa.cpp.

◆ Kmax

#define Kmax   7

Definition at line 572 of file OSdtoa.cpp.

◆ Bcopy

#define Bcopy ( x,
y )
Value:
memcpy((char *)&x->sign, (char *)&y->sign, \
y->wds*sizeof(Long) + 2*sizeof(int))
#define Long
Definition OSdtoa.cpp:37

Definition at line 656 of file OSdtoa.cpp.

◆ d0 [1/2]

#define d0   word0(&d)

◆ d1 [1/2]

#define d1   word1(&d)

◆ d0 [2/2]

#define d0   word0(d)

◆ d1 [2/2]

#define d1   word1(d)

◆ Scale_Bit

#define Scale_Bit   0x10

Definition at line 1519 of file OSdtoa.cpp.

◆ n_bigtens

#define n_bigtens   5

Definition at line 1520 of file OSdtoa.cpp.

◆ Need_Hexdig

#define Need_Hexdig

Definition at line 1536 of file OSdtoa.cpp.

◆ NAN_WORD0

#define NAN_WORD0   0x7ff80000

Definition at line 1592 of file OSdtoa.cpp.

◆ NAN_WORD1

#define NAN_WORD1   0

Definition at line 1596 of file OSdtoa.cpp.

◆ ULbits

#define ULbits   16

Definition at line 1694 of file OSdtoa.cpp.

◆ kshift

#define kshift   4

Definition at line 1695 of file OSdtoa.cpp.

◆ kmask

#define kmask   15

Definition at line 1696 of file OSdtoa.cpp.

Typedef Documentation

◆ ULong

typedef unsigned Long ULong

end of OS code, below is David Gay, except as noted above

Definition at line 239 of file OSdtoa.cpp.

◆ BCinfo

typedef struct BCinfo BCinfo

Definition at line 538 of file OSdtoa.cpp.

◆ Bigint

typedef struct Bigint Bigint

Definition at line 587 of file OSdtoa.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
Round_zero 
Round_near 
Round_up 
Round_down 

Definition at line 1798 of file OSdtoa.cpp.

Function Documentation

◆ Balloc()

static Bigint * Balloc ( int k)
static

Definition at line 592 of file OSdtoa.cpp.

◆ Bfree()

static void Bfree ( Bigint * v)
static

Definition at line 633 of file OSdtoa.cpp.

◆ multadd()

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

Definition at line 660 of file OSdtoa.cpp.

◆ s2b()

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

Definition at line 717 of file OSdtoa.cpp.

◆ hi0bits()

static int hi0bits ( ULong x)
static

Definition at line 755 of file OSdtoa.cpp.

◆ lo0bits()

static int lo0bits ( ULong * y)
static

Definition at line 789 of file OSdtoa.cpp.

◆ i2b()

static Bigint * i2b ( int i)
static

Definition at line 837 of file OSdtoa.cpp.

◆ mult()

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

Definition at line 853 of file OSdtoa.cpp.

◆ pow5mult()

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

Definition at line 965 of file OSdtoa.cpp.

◆ lshift()

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

Definition at line 1022 of file OSdtoa.cpp.

◆ cmp()

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

Definition at line 1082 of file OSdtoa.cpp.

◆ diff()

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

Definition at line 1116 of file OSdtoa.cpp.

◆ ulp()

static double ulp ( U * x)
static

Definition at line 1210 of file OSdtoa.cpp.

◆ b2d()

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

Definition at line 1252 of file OSdtoa.cpp.

◆ d2b()

static Bigint * d2b ( U * d,
int * e,
int * bits )
static

Definition at line 1322 of file OSdtoa.cpp.

◆ ratio()

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

Definition at line 1456 of file OSdtoa.cpp.

◆ match()

static int match ( const char ** sp,
const char * t )
static

Definition at line 1600 of file OSdtoa.cpp.

◆ hexnan()

static void hexnan ( U * rvp,
const char ** sp )
static

Definition at line 1622 of file OSdtoa.cpp.

◆ increment()

static Bigint * increment ( Bigint * b)
static

Definition at line 1704 of file OSdtoa.cpp.

◆ rshift()

static void rshift ( Bigint * b,
int k )
static

Definition at line 1739 of file OSdtoa.cpp.

◆ any_on()

static ULong any_on ( Bigint * b,
int k )
static

Definition at line 1772 of file OSdtoa.cpp.

◆ os_gethex()

void os_gethex ( CONST char ** sp,
U * rvp,
int rounding,
int sign )

Definition at line 1810 of file OSdtoa.cpp.

◆ dshift()

static int dshift ( Bigint * b,
int p2 )
static

NO_HEX_FP}

Definition at line 2171 of file OSdtoa.cpp.

◆ quorem()

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

Definition at line 2181 of file OSdtoa.cpp.

◆ sulp()

static double sulp ( U * x,
BCinfo * bc )
static

Definition at line 2306 of file OSdtoa.cpp.

◆ bigcomp()

static void bigcomp ( U * rv,
const char * s0,
BCinfo * bc )
static

Definition at line 2328 of file OSdtoa.cpp.

◆ os_strtod()

double os_strtod ( const char * s00,
char ** se )

Definition at line 2537 of file OSdtoa.cpp.

◆ rv_alloc()

static char * rv_alloc ( int i)
static

Definition at line 3617 of file OSdtoa.cpp.

◆ nrv_alloc()

static char * nrv_alloc ( const char * s,
char ** rve,
int n )
static

Definition at line 3640 of file OSdtoa.cpp.

◆ os_freedtoa()

void os_freedtoa ( char * s)

Definition at line 3662 of file OSdtoa.cpp.

◆ os_dtoa()

char * os_dtoa ( double dd,
int mode,
int ndigits,
int * decpt,
int * sign,
char ** rve )

Definition at line 3709 of file OSdtoa.cpp.

Variable Documentation

◆ private_mem

double private_mem[PRIVATE_mem]
static

Definition at line 277 of file OSdtoa.cpp.

◆ pmem_next

double * pmem_next = private_mem
static

Definition at line 277 of file OSdtoa.cpp.

◆ freelist

Bigint* freelist[Kmax+1]
static

Definition at line 589 of file OSdtoa.cpp.

◆ p5s

Bigint* p5s
static

Definition at line 962 of file OSdtoa.cpp.

◆ tens

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 1497 of file OSdtoa.cpp.

◆ bigtens

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

Definition at line 1508 of file OSdtoa.cpp.

◆ tinytens

CONST double tinytens[]
static
Initial value:
= { 1e-16, 1e-32, 1e-64, 1e-128,
9007199254740992.*9007199254740992.e-256
}

Definition at line 1509 of file OSdtoa.cpp.

◆ hexdig

unsigned char hexdig[256]
static
Initial value:
= {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
16,17,18,19,20,21,22,23,24,25,0,0,0,0,0,0,
0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
}

Definition at line 1568 of file OSdtoa.cpp.

◆ dtoa_result

char* dtoa_result
static

Definition at line 3610 of file OSdtoa.cpp.