Replying to the four proposals you sent in one mail for easier discussion:

OK.  I've replied to your replies in this thread as 4 short posts.

*** More constants on Number ***
EPSILON would be a sensible addition - I am aware of use cases in
estimating error bounds.  For MIN_NORMAL, MAX_INTEGER and MAX_POWTWO, what
use cases do you have in mind?

EPSILON (defined as 2^-52) is the least-significant bit of the significand
of an IEEE binary64 floating-point number (e.g. JS's Number).  This makes it
easy to find the next larger or smaller representable number.  All the bits
below EPSILON are rounded in the significand to form the EPSILON bit.

MAX_INTEGER is useful when working with integers e.g. prime numbers,
factorials, fibonacci numbers - just as MAX_VALUE is useful.  If an integer
calculation goes over MAX_INTEGER then the result is not properly
significant.

MIN_NORMAL is the smallest floating-point number that retains full
significance.  If a calculation goes below this number then the final result
is known not to be fully significant but has underflowed (gracefully).  (If
a calculation overflows then we know about it like a punch in the face
because the final result is Infinity.)  Functions like ulp, nextUp, nextDown
need to handle numbers below MIN_NORMAL carefully.  Also see scaling below.

MAX_POWTWO is the most significant bit in a Number.  This is useful for
upwardly scaling a number x<1, whereas MIN_NORMAL is useful for downwardly
scaling a number x>1.  It is also useful when taking the ulp of a very large
number x>9e307 which cannot be calculated with the usual trick due to
overflow (admittedly very few people will get excited by this).

Here's an example of scaling using MAX_POWTWO and MIN_NORMAL:

 // multiply x by 2^n, first taking care for large |n|
 if (isFinite( n )) {
   while (n > 1023  &&  1/x != 0) {
     x *= MAX_POWTWO;
     n -= 1023;
   }
   while (n < -1022  &&  x != 0) {
     x *= MIN_NORMAL;
     n += 1022;
   }
 }
 result = x * Math.pow( 2, n )





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

Reply via email to