Maximum number

Discussion in 'Javascript' started by chirs, Oct 4, 2003.

  1. chirs

    chirs Guest

    Hi,

    What is the maximum number in JavaScript? I tried a large number like
    0xff...ff with 30 fs, it still gives me a number, not an infinity. I
    use IE6.

    Thanks.
     
    chirs, Oct 4, 2003
    #1
    1. Advertising

  2. (chirs) writes:

    > What is the maximum number in JavaScript? I tried a large number like
    > 0xff...ff with 30 fs, it still gives me a number, not an infinity. I
    > use IE6.


    Javascript uses IEEE-754 double precission floating point numbers.
    From the ECMAScript standard:
    ---
    ... of them are normalised, having the form
    s × m × 2^e
    where s is +1 or -1, m is a positive integer less than 2^53 but not less
    than 2^52, and e is an integer ranging from -1074 to 971, inclusive.
    ---
    That means that the maiximal number representable as a Javascript number
    is
    1 * (2^53-1) * 2^971 == 2^1024 - 2^971
    In hexadecimal, that is:

    0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

    (256 hexadecimal digits)

    Writing that hexadecimal number into Javascript, makes it output this
    notation:
    1.7976931348623157e+308

    If you add one more bit, changing the "8" to a "c" in the hexadecimal
    notation, Javascript gives "Infinity". Only that bit matters, changing
    later bits is simply ignored. That is

    0xfffffffffffffbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

    gives the same result as the above, because all the extra one-bits are
    lost due to lack of precission, and they are rounded down.

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Oct 4, 2003
    #2
    1. Advertising

  3. chirs

    chirs Guest

    Thanks a lot for the message.

    IEEE-754 double precission floating point numbers are 64 bits. But
    how can it use 64 bit number field to store 256 hex digits?
     
    chirs, Oct 5, 2003
    #3
  4. (chirs) writes:

    > Thanks a lot for the message.
    >
    > IEEE-754 double precission floating point numbers are 64 bits. But
    > how can it use 64 bit number field to store 256 hex digits?


    It doesn't. It only stores 53 significant bits, and then it uses some
    more bits to tell how many zeroes comes after those.

    That is why
    Math.pow(2,52) != Math.pow(2,52)+1
    but
    Math.pow(2,53) == Math.pow(2,53)+1

    It needs 54 bits to represent 2^53+1 precisely. Since there are only 53 bits
    available, the least significant bit is lost.

    (There are some extra details about how the bits are really used, but
    I think they would only confuze matters here :)
    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Oct 5, 2003
    #4
  5. JRS: In article <>, seen
    in news:comp.lang.javascript, chirs <> posted at Sat, 4 Oct
    2003 12:38:24 :-
    >
    >What is the maximum number in JavaScript? I tried a large number like
    >0xff...ff with 30 fs, it still gives me a number, not an infinity. I
    >use IE6.


    The maximum value of an object of type Number, etc., is about 1.7E308,
    as the native number representation is as an IEEE Double.

    But a programmer is free to construct entities using a different
    notation, and to do arithmetic differently :

    function BigFac(J) { var L = 0, k
    for ( k=1 ; k<=J ; k++ ) L += Math.log(k)
    L *= Math.LOG10E
    return Math.exp((L%1)/Math.LOG10E) + 'E' + Math.floor(L) }

    function TryBig() {
    document.write('Thus<tt> 3333! = ', BigFac(3333), '<\/tt>') }

    gives : Thus 3333! = 1.8497400355653586E10296

    All integers up to and including 2^53 = 9007199254740992, and their
    negatives, can be represented exactly.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
     
    Dr John Stockton, Oct 5, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Philip Townsend

    Error on maximum number of connections exceeded

    Philip Townsend, May 11, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    676
  2. mayur
    Replies:
    2
    Views:
    1,016
    Natty Gur
    Jul 2, 2004
  3. Paul W

    Maximum number of apps. on IIS?

    Paul W, Oct 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    332
    Jeffrey Palermo [MCP]
    Oct 9, 2004
  4. mayur
    Replies:
    2
    Views:
    313
    Armando Hernandez
    Jul 16, 2004
  5. phanhuyich
    Replies:
    4
    Views:
    276
Loading...

Share This Page