1 #ifndef DUK_NUMCONV_H_INCLUDED 2 #define DUK_NUMCONV_H_INCLUDED 3 4 /* 5 * Number-to-string conversion. The semantics of these is very tightly 6 * bound with the Ecmascript semantics required for call sites. 7 */ 8 9 /* Output a specified number of digits instead of using the shortest 10 * form. Used for toPrecision() and toFixed(). 11 */ 12 #define DUK_N2S_FLAG_FIXED_FORMAT (1 << 0) 13 14 /* Force exponential format. Used for toExponential(). */ 15 #define DUK_N2S_FLAG_FORCE_EXP (1 << 1) 16 17 /* If number would need zero padding (for whole number part), use 18 * exponential format instead. E.g. if input number is 12300, 3 19 * digits are generated ("123"), output "1.23e+4" instead of "12300". 20 * Used for toPrecision(). 21 */ 22 #define DUK_N2S_FLAG_NO_ZERO_PAD (1 << 2) 23 24 /* Digit count indicates number of fractions (i.e. an absolute 25 * digit index instead of a relative one). Used together with 26 * DUK_N2S_FLAG_FIXED_FORMAT for toFixed(). 27 */ 28 #define DUK_N2S_FLAG_FRACTION_DIGITS (1 << 3) 29 30 /* 31 * String-to-number conversion 32 */ 33 34 /* Maximum exponent value when parsing numbers. This is not strictly 35 * compliant as there should be no upper limit, but as we parse the 36 * exponent without a bigint, impose some limit. 37 */ 38 #define DUK_S2N_MAX_EXPONENT 1000000000 39 40 /* Trim white space (= allow leading and trailing whitespace) */ 41 #define DUK_S2N_FLAG_TRIM_WHITE (1 << 0) 42 43 /* Allow exponent */ 44 #define DUK_S2N_FLAG_ALLOW_EXP (1 << 1) 45 46 /* Allow trailing garbage (e.g. treat "123foo" as "123) */ 47 #define DUK_S2N_FLAG_ALLOW_GARBAGE (1 << 2) 48 49 /* Allow leading plus sign */ 50 #define DUK_S2N_FLAG_ALLOW_PLUS (1 << 3) 51 52 /* Allow leading minus sign */ 53 #define DUK_S2N_FLAG_ALLOW_MINUS (1 << 4) 54 55 /* Allow 'Infinity' */ 56 #define DUK_S2N_FLAG_ALLOW_INF (1 << 5) 57 58 /* Allow fraction part */ 59 #define DUK_S2N_FLAG_ALLOW_FRAC (1 << 6) 60 61 /* Allow naked fraction (e.g. ".123") */ 62 #define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1 << 7) 63 64 /* Allow empty fraction (e.g. "123.") */ 65 #define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1 << 8) 66 67 /* Allow empty string to be interpreted as 0 */ 68 #define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1 << 9) 69 70 /* Allow leading zeroes (e.g. "0123" -> "123") */ 71 #define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1 << 10) 72 73 /* Allow automatic detection of hex base ("0x" or "0X" prefix), 74 * overrides radix argument and forces integer mode. 75 */ 76 #define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1 << 11) 77 78 /* Allow automatic detection of octal base, overrides radix 79 * argument and forces integer mode. 80 */ 81 #define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1 << 12) 82 83 /* 84 * Prototypes 85 */ 86 87 DUK_INTERNAL_DECL void duk_numconv_stringify(duk_context *ctx, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags); 88 DUK_INTERNAL_DECL void duk_numconv_parse(duk_context *ctx, duk_small_int_t radix, duk_small_uint_t flags); 89 90 #endif /* DUK_NUMCONV_H_INCLUDED */ 91