On 07/12/2013 04:03 PM, Allen Wirfs-Brock wrote:
> are you suggesting that if we want such an function, it should be named
> something else, such as isExactInteger, isPreciseInteger,
> isUnambiguousInteger, etc?
Possibly, but I don't think so. Whether a value is exact or precise is a
function not of the value itself, but of how it was computed. Math.pow(2, 53)
computed that way is an exact value. Math.pow(2, 53) - 1 + 2 is (in IEEE-754
terms) the same value. But it is not exact, because it derived from an inexact
computation. It all depends how you got the value you're passing in.
"isUnambiguousInteger" is in a different league from exact/precise. Assuming a
definition like so, it might be reasonable:
function isUnambiguousInteger(n)
{
if ((n % 1) !== 0)
return false;
return Math.abs(n) < Math.pow(2, 53);
}
I'm not sure whether it would be useful enough to carry weight, tho, given it
has fairly esoteric use cases. And anyone asking these sorts of questions
really needs to know the IEEE-754 design well enough to understand how/why
things go wrong, well enough that they could code it themselves. The existence
of such a method doesn't make it any more likely that they will understand
these details.
Jeff
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss