/Users/kmartin/Documents/files/code/cpp/OScpp/COIN-OS/OS/src/OSUtils/OSdtoa.cpp File Reference

#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 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)
static int hi0bits (register 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 (double x)
static double b2d (Bigint *a, int *e)
static Bigintd2b (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 Bigintfreelist [Kmax+1]
static Bigintp5s
static CONST double tens []
static CONST double bigtens [] = { 1e16, 1e32, 1e64, 1e128, 1e256 }
static CONST double tinytens []
static char * dtoa_result


Define Documentation

#define IEEE_8087

the following is OS code put bigendian check here

Definition at line 182 of file OSdtoa.cpp.

#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

Definition at line 200 of file OSdtoa.cpp.

Referenced by os_dtoa(), os_strtod(), s2b(), and ulp().

#define Intcast   (int)(long)

Definition at line 201 of file OSdtoa.cpp.

Referenced by OSnl2osil::walkTree().

#define MALLOC   malloc

Definition at line 243 of file OSdtoa.cpp.

Referenced by Balloc().

#define PRIVATE_MEM   2304

Definition at line 248 of file OSdtoa.cpp.

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

Definition at line 250 of file OSdtoa.cpp.

Referenced by Balloc().

#define IEEE_Arith

Definition at line 260 of file OSdtoa.cpp.

Referenced by os_strtod().

#define INFNAN_CHECK

Definition at line 266 of file OSdtoa.cpp.

#define CONST   const

Definition at line 319 of file OSdtoa.cpp.

Referenced by hexnan(), match(), and os_strtod().

#define word0 (  )     ((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 (  )     ((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 (  )     ((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,
 ) 

Value:

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

Definition at line 354 of file OSdtoa.cpp.

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

#define Exp_shift   20

Definition at line 368 of file OSdtoa.cpp.

Referenced by d2b(), os_dtoa(), os_strtod(), and ulp().

#define Exp_shift1   20

Definition at line 369 of file OSdtoa.cpp.

Referenced by os_dtoa().

#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

Definition at line 371 of file OSdtoa.cpp.

Referenced by d2b().

#define Exp_mask   0x7ff00000

Definition at line 372 of file OSdtoa.cpp.

Referenced by hexnan(), os_dtoa(), os_strtod(), and ulp().

#define P   53

Definition at line 373 of file OSdtoa.cpp.

Referenced by d2b(), os_dtoa(), os_strtod(), and ulp().

#define Bias   1023

Definition at line 374 of file OSdtoa.cpp.

Referenced by d2b(), os_dtoa(), and os_strtod().

#define Emin   (-1022)

Definition at line 375 of file OSdtoa.cpp.

Referenced by os_strtod().

#define Exp_1   0x3ff00000

Definition at line 376 of file OSdtoa.cpp.

Referenced by b2d(), os_dtoa(), and os_strtod().

#define Exp_11   0x3ff00000

Definition at line 377 of file OSdtoa.cpp.

Referenced by os_dtoa().

#define Ebits   11

Definition at line 378 of file OSdtoa.cpp.

Referenced by b2d().

#define Frac_mask   0xfffff

Definition at line 379 of file OSdtoa.cpp.

Referenced by d2b(), os_dtoa(), and os_strtod().

#define Frac_mask1   0xfffff

Definition at line 380 of file OSdtoa.cpp.

Referenced by os_dtoa().

#define Ten_pmax   22

Definition at line 381 of file OSdtoa.cpp.

Referenced by os_dtoa(), and os_strtod().

#define Bletch   0x10

Definition at line 382 of file OSdtoa.cpp.

Referenced by os_dtoa().

#define Bndry_mask   0xfffff

Definition at line 383 of file OSdtoa.cpp.

Referenced by os_dtoa(), and os_strtod().

#define Bndry_mask1   0xfffff

Definition at line 384 of file OSdtoa.cpp.

Referenced by os_strtod().

#define LSB   1

Definition at line 385 of file OSdtoa.cpp.

Referenced by os_strtod().

#define Sign_bit   0x80000000

Definition at line 386 of file OSdtoa.cpp.

Referenced by os_dtoa().

#define Log2P   1

Definition at line 387 of file OSdtoa.cpp.

Referenced by os_dtoa(), and os_strtod().

#define Tiny0   0

Definition at line 388 of file OSdtoa.cpp.

Referenced by os_strtod().

#define Tiny1   1

Definition at line 389 of file OSdtoa.cpp.

Referenced by os_strtod().

#define Quick_max   14

Definition at line 390 of file OSdtoa.cpp.

Referenced by os_dtoa().

#define Int_max   14

Definition at line 391 of file OSdtoa.cpp.

Referenced by os_dtoa().

#define Avoid_Underflow

Definition at line 393 of file OSdtoa.cpp.

Referenced by os_strtod().

#define Flt_Rounds   1

Definition at line 403 of file OSdtoa.cpp.

Referenced by os_dtoa(), and os_strtod().

#define Rounding   Flt_Rounds

Definition at line 412 of file OSdtoa.cpp.

Referenced by os_dtoa(), and os_strtod().

#define rounded_product ( a,
 )     a *= b

Definition at line 489 of file OSdtoa.cpp.

Referenced by os_strtod().

#define rounded_quotient ( a,
 )     a /= b

Definition at line 490 of file OSdtoa.cpp.

Referenced by os_strtod().

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

Definition at line 493 of file OSdtoa.cpp.

Referenced by os_strtod().

#define Big1   0xffffffff

Definition at line 494 of file OSdtoa.cpp.

Referenced by os_strtod().

#define FFFFFFFF   0xffffffffUL

Definition at line 503 of file OSdtoa.cpp.

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

#define ACQUIRE_DTOA_LOCK (  ) 

Definition at line 526 of file OSdtoa.cpp.

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

#define FREE_DTOA_LOCK (  ) 

Definition at line 527 of file OSdtoa.cpp.

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

#define Kmax   15

Definition at line 530 of file OSdtoa.cpp.

#define Bcopy ( x,
 ) 

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)

Referenced by b2d(), and d2b().

#define d1   word1(d)

Referenced by b2d(), and d2b().

#define d0   word0(d)

#define d1   word1(d)

#define Scale_Bit   0x10

Definition at line 1472 of file OSdtoa.cpp.

Referenced by os_strtod().

#define n_bigtens   5

Definition at line 1473 of file OSdtoa.cpp.

Referenced by os_dtoa(), and os_strtod().

#define NAN_WORD0   0x7ff80000

Definition at line 1489 of file OSdtoa.cpp.

Referenced by os_strtod().

#define NAN_WORD1   0

Definition at line 1493 of file OSdtoa.cpp.

Referenced by os_strtod().


Typedef Documentation

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.

typedef struct Bigint Bigint

Definition at line 545 of file OSdtoa.cpp.


Function Documentation

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().

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

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().

static Bigint* s2b ( CONST char *  s,
int  nd0,
int  nd,
ULong  y9 
) [static]

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]

Definition at line 708 of file OSdtoa.cpp.

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

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

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().

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

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().

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

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().

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

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().

static int cmp ( Bigint a,
Bigint b 
) [static]

Definition at line 1035 of file OSdtoa.cpp.

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

Referenced by diff(), os_dtoa(), os_strtod(), and quorem().

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

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]

Definition at line 1163 of file OSdtoa.cpp.

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

Referenced by os_strtod().

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

Definition at line 1205 of file OSdtoa.cpp.

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

Referenced by ratio().

static Bigint* d2b ( double  d,
int *  e,
int *  bits 
) [static]

Definition at line 1275 of file OSdtoa.cpp.

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

Referenced by os_dtoa(), and os_strtod().

static double ratio ( Bigint a,
Bigint b 
) [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]

Definition at line 1501 of file OSdtoa.cpp.

References CONST.

Referenced by os_strtod().

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().

static int quorem ( Bigint b,
Bigint S 
) [static]

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]

Definition at line 2612 of file OSdtoa.cpp.

References rv_alloc().

Referenced by os_dtoa().

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().


Variable Documentation

double private_mem[PRIVATE_mem] [static]

Definition at line 251 of file OSdtoa.cpp.

Referenced by Balloc().

double * pmem_next = private_mem [static]

Definition at line 251 of file OSdtoa.cpp.

Referenced by Balloc().

Bigint* freelist[Kmax+1] [static]

Definition at line 547 of file OSdtoa.cpp.

Bigint* p5s [static]

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]

Definition at line 1461 of file OSdtoa.cpp.

Referenced by os_dtoa(), and os_strtod().

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.


Generated on Sat Mar 29 22:38:04 2008 by  doxygen 1.5.3