mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.9 KiB
91 lines
2.9 KiB
12 years ago
|
#ifndef DUK_NUMCONV_H_INCLUDED
|
||
|
#define DUK_NUMCONV_H_INCLUDED
|
||
|
|
||
12 years ago
|
/*
|
||
|
* Number-to-string conversion. The semantics of these is very tightly
|
||
|
* bound with the Ecmascript semantics required for call sites.
|
||
|
*/
|
||
|
|
||
|
/* Output a specified number of digits instead of using the shortest
|
||
|
* form. Used for toPrecision() and toFixed().
|
||
|
*/
|
||
11 years ago
|
#define DUK_N2S_FLAG_FIXED_FORMAT (1 << 0)
|
||
12 years ago
|
|
||
|
/* Force exponential format. Used for toExponential(). */
|
||
11 years ago
|
#define DUK_N2S_FLAG_FORCE_EXP (1 << 1)
|
||
12 years ago
|
|
||
|
/* If number would need zero padding (for whole number part), use
|
||
|
* exponential format instead. E.g. if input number is 12300, 3
|
||
|
* digits are generated ("123"), output "1.23e+4" instead of "12300".
|
||
|
* Used for toPrecision().
|
||
|
*/
|
||
11 years ago
|
#define DUK_N2S_FLAG_NO_ZERO_PAD (1 << 2)
|
||
12 years ago
|
|
||
|
/* Digit count indicates number of fractions (i.e. an absolute
|
||
|
* digit index instead of a relative one). Used together with
|
||
12 years ago
|
* DUK_N2S_FLAG_FIXED_FORMAT for toFixed().
|
||
12 years ago
|
*/
|
||
11 years ago
|
#define DUK_N2S_FLAG_FRACTION_DIGITS (1 << 3)
|
||
12 years ago
|
|
||
12 years ago
|
/*
|
||
|
* String-to-number conversion
|
||
|
*/
|
||
|
|
||
|
/* Maximum exponent value when parsing numbers. This is not strictly
|
||
|
* compliant as there should be no upper limit, but as we parse the
|
||
|
* exponent without a bigint, impose some limit.
|
||
|
*/
|
||
11 years ago
|
#define DUK_S2N_MAX_EXPONENT 1000000000
|
||
12 years ago
|
|
||
|
/* Trim white space (= allow leading and trailing whitespace) */
|
||
11 years ago
|
#define DUK_S2N_FLAG_TRIM_WHITE (1 << 0)
|
||
12 years ago
|
|
||
|
/* Allow exponent */
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_EXP (1 << 1)
|
||
12 years ago
|
|
||
|
/* Allow trailing garbage (e.g. treat "123foo" as "123) */
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_GARBAGE (1 << 2)
|
||
12 years ago
|
|
||
|
/* Allow leading plus sign */
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_PLUS (1 << 3)
|
||
12 years ago
|
|
||
|
/* Allow leading minus sign */
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_MINUS (1 << 4)
|
||
12 years ago
|
|
||
|
/* Allow 'Infinity' */
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_INF (1 << 5)
|
||
12 years ago
|
|
||
|
/* Allow fraction part */
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_FRAC (1 << 6)
|
||
12 years ago
|
|
||
|
/* Allow naked fraction (e.g. ".123") */
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1 << 7)
|
||
12 years ago
|
|
||
|
/* Allow empty fraction (e.g. "123.") */
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1 << 8)
|
||
12 years ago
|
|
||
|
/* Allow empty string to be interpreted as 0 */
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1 << 9)
|
||
12 years ago
|
|
||
|
/* Allow leading zeroes (e.g. "0123" -> "123") */
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1 << 10)
|
||
12 years ago
|
|
||
|
/* Allow automatic detection of hex base ("0x" or "0X" prefix),
|
||
|
* overrides radix argument and forces integer mode.
|
||
|
*/
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1 << 11)
|
||
12 years ago
|
|
||
12 years ago
|
/* Allow automatic detection of octal base, overrides radix
|
||
|
* argument and forces integer mode.
|
||
|
*/
|
||
11 years ago
|
#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1 << 12)
|
||
12 years ago
|
|
||
12 years ago
|
/*
|
||
|
* Prototypes
|
||
|
*/
|
||
|
|
||
10 years ago
|
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);
|
||
|
DUK_INTERNAL_DECL void duk_numconv_parse(duk_context *ctx, duk_small_int_t radix, duk_small_uint_t flags);
|
||
12 years ago
|
|
||
|
#endif /* DUK_NUMCONV_H_INCLUDED */
|