Web Analytics Made Easy -
StatCounter repeated numbers!? - CodingForum

Announcement

Collapse
No announcement yet.

repeated numbers!?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • repeated numbers!?

    Im having a problem with one of my scripts where i need the repeated number to have more digits.

    e.g.: when i use the javascript function Math.abs(1/9); it doesnt repeat the decimal long enough. It only returns the first 17 digits.
    0.1111111111111111

    Is there any way i can increase the number digits to 26 so it would be like 0.1111111111111111111111111.
    adash5000

  • #2
    Hmmm, don't think so.

    What the heck do you need 26 significant digits for anyhow?
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

    Comment


    • #3
      Is there an upper limit on the size of integers? Maybe if you multiplied the original number by 1E26 you'd be able to get the number of digits you want.
      "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

      Comment


      • #4
        i dont get it wat do u mean by 1E26
        adash5000

        Comment


        • #5
          That wouldn't work either, because then you'd get something like 1.111111111111111e+25

          JS just arbitrarily truncates repeating decimals after 16 digits (4 bits) - nothing you can do about it.

          BTW, the upper limit on integers is around 1e308, or, a 1024-bit integer.
          My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
          “Minds are like parachutes. They don't work unless they are open”
          “Maturity is simply knowing when to not be immature”

          Comment


          • #6
            ok w/e i'll just leave it there. My script works anyways
            adash5000

            Comment


            • #7
              cool

              btw - "1e26" means 1 multipled by (10 to the power 26) [iirc]
              "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

              Comment


              • #8
                Originally posted by beetle
                That wouldn't work either, because then you'd get something like 1.111111111111111e+25

                JS just arbitrarily truncates repeating decimals after 16 digits (4 bits) - nothing you can do about it.

                BTW, the upper limit on integers is around 1e308, or, a 1024-bit integer.
                Not quite. The upper limit of precision integers (or true integers) is 2^31-1 (decimal 2 147 483 647). The lower limit being -2^31. The upper limit on a floating point number, including inprecise integers (which are really just floating point numbers that happen to not have any decimals), is around 1.79e308 (1024 bits, really). However, the precision is then limited to 53 bits zero padded up to a maximum of 1024 bits. 53 bits means the largest number that can be represented without truncating it is decimal 9 007 199 254 740 992. Where the decimal point is placed in that number is in essence irrelevant.
                liorean <[[email protected]]>
                Articles: RegEx evolt wsabstract , Named Arguments
                Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
                Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

                Comment


                • #9
                  Not quite. The upper limit of precision integers (or true integers) is 2^31-1 (decimal 2 147 483 647). The lower limit being -2^31.
                  Although JavaScript does not have what would be considered a true integer. All numbers are represented as a double precision floating point number. So the max value is, infact, approximately 1.79E+308.
                  Code:
                  [size=2]<script type="text/javascript">
                  alert("MAX: " + Number.MAX_VALUE);
                  alert("MIN: " + Number.MIN_VALUE);
                  </script>[/size]

                  Comment


                  • #10
                    Originally posted by Jeff Mott
                    Although JavaScript does not have what would be considered a true integer. All numbers are represented as a double precision floating point number. So the max value is, infact, approximately 1.79E+308.
                    Code:
                    [size=2]<script type="text/javascript">
                    alert("MAX: " + Number.MAX_VALUE);
                    alert("MIN: " + Number.MIN_VALUE);
                    </script>[/size]
                    Well, that depends on your view on it. From the outside, you're right. All numbers are represented as IEEE floating point numbers in JavaScript. However, the IEEE floating point numbers has a 32 bit true integer representation on which you can apply integer math; a 53 bit precision for floating point number on which you can apply only floating point math (the number of distinguished bits in a number, or in more plain English, the point at which the number will be truncated and zero padded); a 64 bit minus 53 bit large number base (the number of numbers that can be expressed); and a 1024 bit large number space (the maximum size of a number).
                    liorean <[[email protected]]>
                    Articles: RegEx evolt wsabstract , Named Arguments
                    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
                    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

                    Comment

                    Working...
                    X