As a C-like language JavaScript has hexadecimal integer literals like
0x123ABC.
C99 introduced hexadecimal floating-point literals, see:
http://publib.boulder.ibm.com/infocenter/zos/v1r12/topic/com.ibm.zos.r12.cbclx01/lit_fltpt.htm#lit_fltpt__hex_float_constants
of the general form:
[sign] "0x" [hexdigits] ["." hexdigits] ["p" [sign] decdigits]
(with the proviso that at least one significant hexdigit must appear).
The letter 'p' means "times 2 to the power of"; and the exponent field is
signed decimal. Case is ignored.
(In C the exponent field *must* appear in order to disambiguate a trailing
'f' = float flag, but this would not be necessary in JavaScript.)
Would it be a Big Ask to have hexadecimal floating-point literals in ES6?
It extends the existing hexadecimal integer literal syntax slightly to
encompass all the finite Numbers.
This gives the programmer the ability to precisely specify every bit of a
Number in a well-understood form. And it is a natural match with the
binary64 sign-significand-exponent fields.
For example:
var EPSILON = 1p-52,
MAX_POWTWO = 1p1023;
instead of
var EPSILON = 1 / 0x10000000000000,
MAX_POWTWO = 1 / (Number.MIN_VALUE * 0x8000000000000);
JavaScript Numbers can be integer or fractional, decimal literals too, why
do hexadecimal literals discriminate against fractions?
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss