Announcement

Collapse
No announcement yet.

Increase the Precision of Your Floating Point Literals to 18 Decimal Digits

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

  • Increase the Precision of Your Floating Point Literals to 18 Decimal Digits

    Originally posted by Steve Rossell View Post
    Microsoft altered the 32-bit sub-system of Windows, so that the FPU is initialized to a limited precision of 53 bits of mantissa. Previously, the FPU was initialized to a 64-bit mantissa as designed by Intel.

    We implemented an internal change to compiled executables so that extended precision is guaranteed in run time code. However, evaluation of numeric literals in your compiled programs are currently limited to double precision. This will be increased to extended precision in the next version of PowerBASIC For Windows and the PowerBASIC Console Compiler.
    As indicated in Steve Rossell's post in the thread “64-bit Precision for Extended Precision Variables Guaranteed?,” the precision of floating point literals cast to extended precision results in only double precision. Therefore, the precision is limited to ~ 16 decimal digits. We will have to wait till the next version of PB/CC to obtain extended precision (18 decimal digits) for literals cast as extended precision.

    In the meantime, however, the following code illustrates a simple method for obtaining higher precision (18 decimal digits) for your floating point numeric literals. It involves using the VAL function to convert your literals to extended precision instead of casting them to extended precision; i.e, using VAL("literal") instead of literal##.

    In using this method, note the following:

    (1) If you have a floating point literal which has more than 18 significant digits, round the literal to 18 digits before using it in the string argument of VAL. If you don’t, VAL will truncate any digits beyond the 18 digits (instead of rounding to 18 digits), resulting in less precision.
    (2) You do not have to add zeroes to a floating point literal with fewer than 18 significant digits. (In other words -- with VAL -- using 0.1 will give you the same result as 0.100000000000000000.
    (3) If calculation time matters, do not use the VAL function within a loop with many iterations. It does have considerable overhead. Instead, assign the value of VAL(“literal”) to an extended precision variable and use the variable within the loop.
    (4) If you have any doubt about the value of your literal as obtained from VAL(“literal”), check it out with STR$(VAL(“literal”), 18).
    (5) This procedure has not been fully tested (or vetted), so please use good judgment in its use.

    Any constructive comments relative to this post will be greatly appreciated.

    --WH

    Code:
     
    #COMPILE EXE
    #DIM ALL
     
    FUNCTION PBMAIN() AS LONG
     
    DIM z AS LOCAL EXT, y AS LOCAL EXT, counter AS LOCAL LONG, timecheck AS LOCAL DOUBLE
     
    PRINT "Assigning 0.1 to z with 16 digits of precision"
    z = 0.1##
    PRINT:PRINT "z = 0.1## = ";STR$(z, 18)
     
    PRINT:PRINT:PRINT "Assigning 0.1 to z with 18 digits of precision"
    z = VAL("0.1")
    PRINT:PRINT "z = VAL(""0.1"") = ";STR$(z, 18)
     
    PRINT:PRINT:PRINT "Calculation of 0.1 - 1/10. (Exact result = 0)"
    z = 0.1## - 1/10
    PRINT:PRINT "z = 0.1## - 1/10 = "; STR$(z,18)
     
    PRINT:PRINT:PRINT "Calculation of 0.1 - 1/10. (Exact result = 0)"
    z = VAL("0.1") - 1/10
    PRINT:PRINT "z = VAL(""0.1"") - 1/10 = "; STR$(z,18)
     
    PRINT:PRINT:PRINT "Iteration loop (1 million iterations) using VAL(""0.1"") within the loop"
    timecheck = TIMER
    FOR counter = 1 TO 1000000
      z = VAL("0.1") - 1/10
    NEXT counter
    PRINT "Result: "; STR$(z, 18)
    PRINT "Elapsed time (seconds): ";ROUND(TIMER - timecheck, 4)
     
    PRINT:PRINT:PRINT "Iteration loop (1 million iterations) using EXT y (equal to VAL(""0.1"")) within the loop"
    timecheck = TIMER
    y = VAL("0.1")
    FOR counter = 1 TO 1000000
      z = y - 1/10
    NEXT counter
    PRINT "Result: "; STR$(z, 18)
    PRINT "Elapsed time (seconds): ";ROUND(TIMER - timecheck, 4)
     
    WAITKEY$
     
    END FUNCTION
    Last edited by Walter Henn; 23 Dec 2007, 08:49 PM. Reason: Code Correction

  • #2
    Thank you for an interim solution.
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

    Comment


    • #3
      JFYI. I will soon start the development of an arbitrary precision floating point dll .
      It will be based on the huge integer math routines of HIME.
      Stay tuned ...

      Kind regards
      Eddy

      Comment


      • #4
        Hey Eddy --

        Sounds great! I'm sure there will be a great response to such a capability.

        Thanks,
        Walter

        Comment


        • #5
          This is my most intense wish on that PBCC wishlist! Huge number data in PowerBasic Console Compiler. I’ve been writing about this topic for years. PB doesn’t say much about it…I mean they don’t even consider responding. Exception was a skilled PBCC programmer I came to know as Laitser Edmonds (he is a New Zealander, I believe). Laitser only asked: “Why the need for such huge numbers?” The need is huge, Super Crocodilule. Just think of the DNA sequences and the probability of collisions (duplications) — so important in court trials today. There are many more applications that cry for huge data types (huge as in cosmic…hundreds of googols in size).

          It is very easy to say: “Super Crocodilule, I wrote a great DLL that works with fantastically huge numbers! Say, one million digits in length…I can give you two million digits, if that’s what you want!”

          Important problem: How could one guarantee accuracy? Who could guarantee accuracy, anyway?

          I remember of using a Basic interpreter named UBasic or something (I think created in a Japanese university). They claimed numerical data of some 2000 digits! You kidding me? Well, then I read some serious complaints about the accuracy of the calculations with such numbers!

          There is a company named Microsoft, who, undoubtedly, possesses the largest amount of money in the world. They succeeded to implement a numerical data type of some 300 digits in size (called Currency in Visual Basic 6). Why didn’t they go to 2000 digits (forget about one million)? We can guess, they could find methods to test accuracy only for some 300 digits.

          Now, no offence to any skilled individual programmer. How could I trust your accuracy? Show me how to verify your accuracy! Why doesn’t Microsoft go to astronomical numerical data types? Microsoft has some thousands of programmers with super mathematical training. Can’t they figure out a way to implement — accurately — huge numerical data of many googols in size?

          I wonder why PowerBasic Inc. doesn’t slip a word about this topic?

          I would trust accuracy if it comes from PowerBasic or even Microsoft.

          Ion Saliu,
          Googling At-Large
          www.saliu.com

          Comment


          • #6
            Originally posted by Ion Saliu View Post
            ...I came to know as Laitser Edmonds
            That would be Lance Edmonds. He was the former forum admin here.

            About the rest of your post . I am not sure if there is a real question in there that I could answer...

            Kind regards
            Eddy

            Comment


            • #7
              About the rest of your post . I am not sure if there is a real question in there that I could answer...

              Kind regards
              __________________
              Eddy
              You talking to me? Did I talk to you? You like people ask you questions? What question would you like me to ask you? Okay, then. Question: What is the difference between googol and Google?

              Ion+

              Comment


              • #8
                What is the difference between googol and Google?
                Not much, they are both very big. :stupid:
                Dave.

                You're never too old to learn something stupid.

                Comment


                • #9
                  Definition -

                  A googol is 10 to the 100th power (which is 1 followed by 100 zeros). A googol is larger than the number of elementary particles in the universe, which amount to only 10 to the 80th power.
                  The term was invented by Milton Sirotta, the 9-year nephew of mathematician Edward Kasner, who had asked his nephew what he thought such a large number should be called. Such a number, Milton apparently replied after a short thought, could only be called something as silly as a "googol."

                  Later, another mathematician devised the term googolplex for 10 to the power of googol - that is, 1 followed by 10 to the power of 100 zeros. Frank Pilhofer has determined that, given Moore's Law (which is that computer processor power doubles about every 1 to 2 years), it would make no sense to try to print out a googolplex for another 524 years - since all earlier attempts to print a googolplex out would be overtaken by the faster processor.

                  Larry Page and Sergey Brin, the founders of Google, named their search engine after the term googol. In 1997, Larry was brainstorming names with other Stanford graduate students, including Sean Anderson, and looking at available domain names. Anderson miskeyed googol as "google" and found it available. Larry liked it and the name "Google" stuck. Google's corporate headquarters is called the GooglePlex, an affectionately tongue-in-cheek reference to the origins of the company name.


                  CONTRIBUTORS: Lawrence Lea
                  LAST UPDATED: 07 Dec 2006
                  Regards,
                  Bob

                  Comment


                  • #10
                    Excellent job, Bob!

                    One might make two additions, somehow humoristic.

                    1) Google has 2 O’s, while googol has 100.
                    2) Googol is the great-grandson of the Russian writer Gogol; Google is the brainchild of a Russian immigrant to the U.S.

                    Goooooogle ->

                    Comment


                    • #11
                      I would be very interested to try and buy a dll allowing to work with big floating point numbers.

                      http://gmplib.org/ is an alternative. I will work on it to create declaration file for thinBasic. If able I will post sources. They will be very PB compatible.
                      thinBasic programming language
                      Win10 64bit - 8GB Ram - i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

                      Comment


                      • #12
                        Johan Klassen already did some work here: http://www.powerbasic.com/support/pb...936#post153936
                        thinBasic programming language
                        Win10 64bit - 8GB Ram - i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

                        Comment


                        • #13
                          Also more info here:
                          http://purebasic.fr/english/viewtopi...&highlight=gmp
                          thinBasic programming language
                          Win10 64bit - 8GB Ram - i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

                          Comment


                          • #14
                            While gmplib provides very high precision for functions included in the library, it does not contain transcendental functions (sin, cos, tan, asin, acos, atan, etc.) or log functions (log10, log2, ln, 10^x, 2^x, e^x, x^y, etc., where x and y are floating point numbers). This is unfortunate since scientists often need higher precision for these functions.

                            If anyone is aware of high precision floating point software packages that contain these functions, please post here.

                            Thanks,
                            WH

                            Comment


                            • #15
                              Walter,
                              If anyone is aware of high precision floating point software packages that contain these functions, please post here
                              Windows Calculator does them to 32 digits.
                              Start/All Programs/Accesories/Calculator

                              Windows Power Toy Calculator I think does them to 512 digits.
                              http://www.microsoft.com/windowsxp/d...powertoys.mspx


                              UBASIC does them to 2600 digits.
                              http://archives.math.utk.edu/softwar...theory/ubasic/


                              Paul.

                              Comment


                              • #16
                                The Microsoft Calculator Plus adds conversion functions to the Windows Calculator. It is also accurate to 32 digits.

                                The PowerToy Calculator does not install under Windows Vista (but it can be run), Microsoft needs to update the PowerToys for Vista.


                                Last edited by Greg Lyon; 27 Dec 2007, 01:16 AM. Reason: additional info

                                Comment


                                • #17
                                  Thanks for your input, Paul.

                                  When I indicated floating point software packages, I did not mean a calculator program, such as Windows Calculator or Windows Power Toy Calculator. (I have the Power Toy Calculator on my computer and it's an extremely valuable resource that I use frequently. It has user-selectable 32, 64, 128 or 512 digits of precision.)

                                  With regard to UBasic, I'm still looking into it. One disappointment is that it's for a DOS environment, although it can be run in a DOS window.

                                  Frankly, I was hoping to find a library, like libgmp, that can be used within PB/CC.

                                  WH

                                  Comment


                                  • #18
                                    >Frankly, I was hoping to find a library, like libgmp, that can be used within PB/CC.

                                    I did a quick "Google" for math libraries but got too many hits for the results to be useful.

                                    But I have to believe the 'code' sites like code project, sourceforge, etc simply must offer libraries for Windows developers. For that matter there have to be suggestions and recommendations right here from PB users for math libraries somewhere in these ten-plus years and 100,000+ postings.

                                    As fars as "like [gmplib]" .....I just looked at the gmplib home page at http://gmplib.org.

                                    Doesn't the download include executable Dynamic Link Library files for Windows? If not, maybe you can find someone who has compiled a DLL, or will compile it for you.

                                    As long as you can get the library as a DLL, you can use it with PB/CC.
                                    Michael Mattias
                                    Tal Systems Inc. (retired)
                                    Racine WI USA
                                    [email protected]
                                    http://www.talsystems.com

                                    Comment


                                    • #19
                                      Originally posted by Michael Mattias View Post

                                      As fars as "like [gmplib]" .....I just looked at the gmplib home page at http://gmplib.org.

                                      Doesn't the download include executable Dynamic Link Library files for Windows? If not, maybe you can find someone who has compiled a DLL, or will compile it for you. As long as you can get the library as a DLL, you can use it with PB/CC.
                                      Originally posted by Walter Henn View Post

                                      While gmplib provides very high precision for functions included in the library, it does not contain transcendental functions (sin, cos, tan, asin, acos, atan, etc.) or log functions (log10, log2, ln, 10^x, 2^x, e^x, x^y, etc., where x and y are floating point numbers). This is unfortunate since scientists often need higher precision for these functions.

                                      If anyone is aware of high precision floating point software packages that contain these functions, please post here.
                                      Thanks for your reply, Michael. I have tried gmplib (with the libgmp-3.dll) and am quite pleased with its capabilities; it just doesn't have transcendental functions.

                                      --WH
                                      Last edited by Walter Henn; 29 Dec 2007, 06:31 PM. Reason: Correction of filename from "libgmp_3.dll" to "libgmp-3.dll".

                                      Comment


                                      • #20
                                        Walter,

                                        Where did you find "libgmp_3.dll" ? Google comes up with nothing. I downloaded some tar files from http://gmplib.org/#DOWNLOAD and found nothing.
                                        Regards,
                                        Bob

                                        Comment

                                        Working...
                                        X