Numerical Analysts don't really want the actual bit strings of s-m-e. They want the values.

The ancient C functions frexp/ldexp are great for this (see also modf(3)).

frexp/ldexp were created before 1980 -- before IEEE754 was even a glint in William Kahan's eye. So they are not quite the same as logB/scaleB and split/join-type functions. frexp(3) delivers a significand in the interval [0.5,1) not [1,2) union 0, and it is a bit weird with the sign. ldexp(3) is almost perfect as scaleB.

--------------------------------------------------
From: "David Herman" <[email protected]>
Technically you don't even need typed arrays to do it; it's just more work to implement a "pure" library that extracts the bit strings. With typed arrays it was utterly trivial (though you have to be slightly careful to avoid writing unportable code.)

FWIW.

Dave

On Mar 21, 2012, at 12:00 AM, Brendan Eich wrote:

Not gonna change number (the primitive type) to IEEE 754r DFP (not sure you were getting at that in closing). Just FTR.

These Number.prototype getters can be implemented today in top browsers (thanks to typed arrays) and in ES6 (binary data embraces and extends typed arrays). See https://github.com/dherman/float.js/.

/be

Roger Andrews wrote:
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

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to