Floating-point numbers are formed of a sign (s), significand (m), exponent (e), and radix (b):
    (-1)^s * m * b^e
where 0<=m<b.

Often we want to access the s-m-e values directly, especially the significand. Notably when doing comparison for approximate equality by "masking out" the rounding error in the low order bits; or some multiprecise work. In ES5 this is painful.

The sign, significand, exponent, radix are intrinsic properties of a Number (like the length of a String) - so how about exposing them as properties of Number? Say the sign, significand, and exponent could be read-write and the radix read-only.

Advantages:
1)  extracting the significand is easy:
       x.signif
2)  scaling is easy (scaleB operation):
       x.exponent += N
3)  the logB operation is easy:
       x.exponent

Also programmers could distinguish a binary value from a decimal without using typeof, using the 'radix' property instead. This might future-proof against the possible coming of a Decimal type without breaking existing code. Does it help there?
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to