libgpac
Documentation of the core library of GPAC
Loading...
Searching...
No Matches
dtoa.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <inttypes.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <sys/time.h>
#include <math.h>
#include <setjmp.h>
#include "cutils.h"
#include "dtoa.h"
+ Include dependency graph for dtoa.c:

Data Structures

struct  mpb_t
 

Macros

#define USE_POW5_TABLE
 
#define USE_FAST_INT
 
#define LIMB_LOG2_BITS   5
 
#define LIMB_BITS   (1 << LIMB_LOG2_BITS)
 
#define LIMB_DIGITS   9
 
#define JS_RADIX_MAX   36
 
#define DBIGNUM_LEN_MAX   52 /* ~ 2^(1072+53)*36^100 (dtoa) */
 
#define MANT_LEN_MAX   18 /* < 36^100 */
 
#define MUL_LOG2_RADIX_BASE_LOG2   24
 

Typedefs

typedef int32_t slimb_t
 
typedef uint32_t limb_t
 
typedef uint64_t dlimb_t
 
typedef intptr_t mp_size_t
 

Enumerations

enum  { JS_RNDN , JS_RNDNA , JS_RNDZ }
 

Functions

static limb_t mp_add_ui (limb_t *tab, limb_t b, size_t n)
 
static limb_t mp_mul1 (limb_t *tabr, const limb_t *taba, limb_t n, limb_t b, limb_t l)
 
static limb_t udiv1norm_init (limb_t d)
 
static limb_t udiv1norm (limb_t *pr, limb_t a1, limb_t a0, limb_t d, limb_t d_inv)
 
static limb_t mp_div1 (limb_t *tabr, const limb_t *taba, limb_t n, limb_t b, limb_t r)
 
static limb_t mp_shr (limb_t *tab_r, const limb_t *tab, mp_size_t n, int shift, limb_t high)
 
static limb_t mp_shl (limb_t *tab_r, const limb_t *tab, mp_size_t n, int shift, limb_t low)
 
static no_inline limb_t mp_div1norm (limb_t *tabr, const limb_t *taba, limb_t n, limb_t b, limb_t r, limb_t b_inv, int shift)
 
static __maybe_unused void mpb_dump (const char *str, const mpb_t *a)
 
static void mpb_renorm (mpb_t *r)
 
static uint64_t pow_ui (uint32_t a, uint32_t b)
 
static uint32_t pow_ui_inv (uint32_t *pr_inv, int *pshift, uint32_t a, uint32_t b)
 
static int mpb_get_bit (const mpb_t *r, int k)
 
static void mpb_shr_round (mpb_t *r, int shift, int rnd_mode)
 
static int mpb_cmp (const mpb_t *a, const mpb_t *b)
 
static void mpb_set_u64 (mpb_t *r, uint64_t m)
 
static uint64_t mpb_get_u64 (mpb_t *r)
 
static int mpb_floor_log2 (mpb_t *a)
 
static int mul_log2_radix (int a, int radix)
 
static void u32toa_len (char *buf, uint32_t n, size_t len)
 
static void u64toa_bin_len (char *buf, uint64_t n, unsigned int radix_bits, int len)
 
static void limb_to_a (char *buf, limb_t n, unsigned int radix, int len)
 
size_t u32toa (char *buf, uint32_t n)
 
size_t i32toa (char *buf, int32_t n)
 
size_t u64toa (char *buf, uint64_t n)
 
size_t i64toa (char *buf, int64_t n)
 
size_t u64toa_radix (char *buf, uint64_t n, unsigned int radix)
 
size_t i64toa_radix (char *buf, int64_t n, unsigned int radix)
 
static int output_digits (char *buf, mpb_t *a, int radix, int n_digits1, int dot_pos)
 
static int mul_pow (mpb_t *a, int radix1, int radix_shift, int f, BOOL is_int, int e)
 
static void mul_pow_round (mpb_t *tmp1, uint64_t m, int e, int radix1, int radix_shift, int f, int rnd_mode)
 
static uint64_t round_to_d (int *pe, mpb_t *a, int e_offset, int rnd_mode)
 
static uint64_t mul_pow_round_to_d (int *pe, mpb_t *a, int radix1, int radix_shift, int f, int rnd_mode)
 
int js_dtoa_max_len (double d, int radix, int n_digits, int flags)
 
static void * dtoa_malloc (uint64_t **pptr, size_t size)
 
static void dtoa_free (void *ptr)
 
int js_dtoa (char *buf, double d, int radix, int n_digits, int flags, JSDTOATempMem *tmp_mem)
 
static int to_digit (int c)
 
static void mpb_mul1_base (mpb_t *r, limb_t radix_base, limb_t a)
 
double js_atod (const char *str, const char **pnext, int radix, int flags, JSATODTempMem *tmp_mem)
 

Variables

static const uint32_t pow5_table [17]
 
static const uint8_t pow5h_table [4]
 
static const uint32_t pow5_inv_table [13]
 
static const uint32_t mul_log2_radix_table [JS_RADIX_MAX - 1]
 
static const uint8_t digits_per_limb_table [JS_RADIX_MAX - 1]
 
static const uint32_t radix_base_table [JS_RADIX_MAX - 1]
 
static uint8_t dtoa_max_digits_table [JS_RADIX_MAX - 1]
 
static uint8_t atod_max_digits_table [JS_RADIX_MAX - 1]
 
static const int16_t max_exponent [JS_RADIX_MAX - 1]
 
static const int16_t min_exponent [JS_RADIX_MAX - 1]
 

Data Structure Documentation

◆ mpb_t

struct mpb_t
Data Fields
int len
limb_t tab[]

Macro Definition Documentation

◆ USE_POW5_TABLE

#define USE_POW5_TABLE

◆ USE_FAST_INT

#define USE_FAST_INT

◆ LIMB_LOG2_BITS

#define LIMB_LOG2_BITS   5

◆ LIMB_BITS

#define LIMB_BITS   (1 << LIMB_LOG2_BITS)

◆ LIMB_DIGITS

#define LIMB_DIGITS   9

◆ JS_RADIX_MAX

#define JS_RADIX_MAX   36

◆ DBIGNUM_LEN_MAX

#define DBIGNUM_LEN_MAX   52 /* ~ 2^(1072+53)*36^100 (dtoa) */

◆ MANT_LEN_MAX

#define MANT_LEN_MAX   18 /* < 36^100 */

◆ MUL_LOG2_RADIX_BASE_LOG2

#define MUL_LOG2_RADIX_BASE_LOG2   24

Typedef Documentation

◆ slimb_t

typedef int32_t slimb_t

◆ limb_t

typedef uint32_t limb_t

◆ dlimb_t

typedef uint64_t dlimb_t

◆ mp_size_t

typedef intptr_t mp_size_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
JS_RNDN 
JS_RNDNA 
JS_RNDZ 

Function Documentation

◆ mp_add_ui()

static limb_t mp_add_ui ( limb_t tab,
limb_t  b,
size_t  n 
)
static
+ Here is the caller graph for this function:

◆ mp_mul1()

static limb_t mp_mul1 ( limb_t tabr,
const limb_t taba,
limb_t  n,
limb_t  b,
limb_t  l 
)
static
+ Here is the caller graph for this function:

◆ udiv1norm_init()

static limb_t udiv1norm_init ( limb_t  d)
static
+ Here is the caller graph for this function:

◆ udiv1norm()

static limb_t udiv1norm ( limb_t pr,
limb_t  a1,
limb_t  a0,
limb_t  d,
limb_t  d_inv 
)
static
+ Here is the caller graph for this function:

◆ mp_div1()

static limb_t mp_div1 ( limb_t tabr,
const limb_t taba,
limb_t  n,
limb_t  b,
limb_t  r 
)
static
+ Here is the caller graph for this function:

◆ mp_shr()

static limb_t mp_shr ( limb_t tab_r,
const limb_t tab,
mp_size_t  n,
int  shift,
limb_t  high 
)
static
+ Here is the caller graph for this function:

◆ mp_shl()

static limb_t mp_shl ( limb_t tab_r,
const limb_t tab,
mp_size_t  n,
int  shift,
limb_t  low 
)
static
+ Here is the caller graph for this function:

◆ mp_div1norm()

static no_inline limb_t mp_div1norm ( limb_t tabr,
const limb_t taba,
limb_t  n,
limb_t  b,
limb_t  r,
limb_t  b_inv,
int  shift 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpb_dump()

static __maybe_unused void mpb_dump ( const char *  str,
const mpb_t a 
)
static

◆ mpb_renorm()

static void mpb_renorm ( mpb_t r)
static
+ Here is the caller graph for this function:

◆ pow_ui()

static uint64_t pow_ui ( uint32_t  a,
uint32_t  b 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pow_ui_inv()

static uint32_t pow_ui_inv ( uint32_t pr_inv,
int *  pshift,
uint32_t  a,
uint32_t  b 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpb_get_bit()

static int mpb_get_bit ( const mpb_t r,
int  k 
)
static
+ Here is the caller graph for this function:

◆ mpb_shr_round()

static void mpb_shr_round ( mpb_t r,
int  shift,
int  rnd_mode 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpb_cmp()

static int mpb_cmp ( const mpb_t a,
const mpb_t b 
)
static
+ Here is the caller graph for this function:

◆ mpb_set_u64()

static void mpb_set_u64 ( mpb_t r,
uint64_t  m 
)
static
+ Here is the caller graph for this function:

◆ mpb_get_u64()

static uint64_t mpb_get_u64 ( mpb_t r)
static
+ Here is the caller graph for this function:

◆ mpb_floor_log2()

static int mpb_floor_log2 ( mpb_t a)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mul_log2_radix()

static int mul_log2_radix ( int  a,
int  radix 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ u32toa_len()

static void u32toa_len ( char *  buf,
uint32_t  n,
size_t  len 
)
static
+ Here is the caller graph for this function:

◆ u64toa_bin_len()

static void u64toa_bin_len ( char *  buf,
uint64_t  n,
unsigned int  radix_bits,
int  len 
)
static
+ Here is the caller graph for this function:

◆ limb_to_a()

static void limb_to_a ( char *  buf,
limb_t  n,
unsigned int  radix,
int  len 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ u32toa()

size_t u32toa ( char *  buf,
uint32_t  n 
)
+ Here is the caller graph for this function:

◆ i32toa()

size_t i32toa ( char *  buf,
int32_t  n 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ u64toa()

size_t u64toa ( char *  buf,
uint64_t  n 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ i64toa()

size_t i64toa ( char *  buf,
int64_t  n 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ u64toa_radix()

size_t u64toa_radix ( char *  buf,
uint64_t  n,
unsigned int  radix 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ i64toa_radix()

size_t i64toa_radix ( char *  buf,
int64_t  n,
unsigned int  radix 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ output_digits()

static int output_digits ( char *  buf,
mpb_t a,
int  radix,
int  n_digits1,
int  dot_pos 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mul_pow()

static int mul_pow ( mpb_t a,
int  radix1,
int  radix_shift,
int  f,
BOOL  is_int,
int  e 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mul_pow_round()

static void mul_pow_round ( mpb_t tmp1,
uint64_t  m,
int  e,
int  radix1,
int  radix_shift,
int  f,
int  rnd_mode 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ round_to_d()

static uint64_t round_to_d ( int *  pe,
mpb_t a,
int  e_offset,
int  rnd_mode 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mul_pow_round_to_d()

static uint64_t mul_pow_round_to_d ( int *  pe,
mpb_t a,
int  radix1,
int  radix_shift,
int  f,
int  rnd_mode 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ js_dtoa_max_len()

int js_dtoa_max_len ( double  d,
int  radix,
int  n_digits,
int  flags 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dtoa_malloc()

static void * dtoa_malloc ( uint64_t **  pptr,
size_t  size 
)
static
+ Here is the caller graph for this function:

◆ dtoa_free()

static void dtoa_free ( void *  ptr)
static
+ Here is the caller graph for this function:

◆ js_dtoa()

int js_dtoa ( char *  buf,
double  d,
int  radix,
int  n_digits,
int  flags,
JSDTOATempMem tmp_mem 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_digit()

static int to_digit ( int  c)
static
+ Here is the caller graph for this function:

◆ mpb_mul1_base()

static void mpb_mul1_base ( mpb_t r,
limb_t  radix_base,
limb_t  a 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ js_atod()

double js_atod ( const char *  str,
const char **  pnext,
int  radix,
int  flags,
JSATODTempMem tmp_mem 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ pow5_table

const uint32_t pow5_table[17]
static
Initial value:
= {
0x00000005, 0x00000019, 0x0000007d, 0x00000271,
0x00000c35, 0x00003d09, 0x0001312d, 0x0005f5e1,
0x001dcd65, 0x009502f9, 0x02e90edd, 0x0e8d4a51,
0x48c27395, 0x6bcc41e9, 0x1afd498d, 0x86f26fc1,
0xa2bc2ec5,
}

◆ pow5h_table

const uint8_t pow5h_table[4]
static
Initial value:
= {
0x00000001, 0x00000007, 0x00000023, 0x000000b1,
}

◆ pow5_inv_table

const uint32_t pow5_inv_table[13]
static
Initial value:
= {
0x99999999, 0x47ae147a, 0x0624dd2f, 0xa36e2eb1,
0x4f8b588e, 0x0c6f7a0b, 0xad7f29ab, 0x5798ee23,
0x12e0be82, 0xb7cdfd9d, 0x5fd7fe17, 0x19799812,
0xc25c2684,
}

◆ mul_log2_radix_table

const uint32_t mul_log2_radix_table[JS_RADIX_MAX - 1]
static
Initial value:
= {
0x000000, 0xa1849d, 0x000000, 0x6e40d2,
0x6308c9, 0x5b3065, 0x000000, 0x50c24e,
0x4d104d, 0x4a0027, 0x4768ce, 0x452e54,
0x433d00, 0x418677, 0x000000, 0x3ea16b,
0x3d645a, 0x3c43c2, 0x3b3b9a, 0x3a4899,
0x39680b, 0x3897b3, 0x37d5af, 0x372069,
0x367686, 0x35d6df, 0x354072, 0x34b261,
0x342bea, 0x33ac62, 0x000000, 0x32bfd9,
0x3251dd, 0x31e8d6, 0x318465,
}

◆ digits_per_limb_table

const uint8_t digits_per_limb_table[JS_RADIX_MAX - 1]
static
Initial value:
= {
64,40,32,27,24,22,21,20,19,18,17,17,16,16,16,15,15,15,14,14,14,14,13,13,13,13,13,13,13,12,12,12,12,12,12,
}

◆ radix_base_table

const uint32_t radix_base_table[JS_RADIX_MAX - 1]
static
Initial value:
= {
0x00000000, 0xcfd41b91, 0x00000000, 0x48c27395,
0x81bf1000, 0x75db9c97, 0x40000000, 0xcfd41b91,
0x3b9aca00, 0x8c8b6d2b, 0x19a10000, 0x309f1021,
0x57f6c100, 0x98c29b81, 0x00000000, 0x18754571,
0x247dbc80, 0x3547667b, 0x4c4b4000, 0x6b5a6e1d,
0x94ace180, 0xcaf18367, 0x0b640000, 0x0e8d4a51,
0x1269ae40, 0x17179149, 0x1cb91000, 0x23744899,
0x2b73a840, 0x34e63b41, 0x40000000, 0x4cfa3cc1,
0x5c13d840, 0x6d91b519, 0x81bf1000,
}

◆ dtoa_max_digits_table

uint8_t dtoa_max_digits_table[JS_RADIX_MAX - 1]
static
Initial value:
= {
54, 35, 28, 24, 22, 20, 19, 18, 17, 17, 16, 16, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12,
}

◆ atod_max_digits_table

uint8_t atod_max_digits_table[JS_RADIX_MAX - 1]
static
Initial value:
= {
64, 80, 32, 55, 49, 45, 21, 40, 38, 37, 35, 34, 33, 32, 16, 31, 30, 30, 29, 29, 28, 28, 27, 27, 27, 26, 26, 26, 26, 25, 12, 25, 25, 24, 24,
}

◆ max_exponent

const int16_t max_exponent[JS_RADIX_MAX - 1]
static
Initial value:
= {
1024, 647, 512, 442, 397, 365, 342, 324,
309, 297, 286, 277, 269, 263, 256, 251,
246, 242, 237, 234, 230, 227, 224, 221,
218, 216, 214, 211, 209, 207, 205, 203,
202, 200, 199,
}

◆ min_exponent

const int16_t min_exponent[JS_RADIX_MAX - 1]
static
Initial value:
= {
-1075, -679, -538, -463, -416, -383, -359, -340,
-324, -311, -300, -291, -283, -276, -269, -263,
-258, -254, -249, -245, -242, -238, -235, -232,
-229, -227, -224, -222, -220, -217, -215, -214,
-212, -210, -208,
}