1. PI routines

--=====================_859198120==_

        I've just begun to explore Euphoria, and thought it would be fun to
transfer a
QBasic PI calculation engine to Euphoria.  Needless to say, the Euphoria
engine is faster than the QBasic version.  See Table 1 for results of my
comparisons.
        However, there is a *minor* bug in the Euphoria version that I
cannot quite figure out.  It seems that it does not want to properly
calculate the last two (2 :) ) digits of PI.  ie, when calculating to 50
digits,  PI.EX responds with:


but PI.BAS returns:


        I have included both PI.EX and PI.BAS for those who would like to
see the source, and for those who have had more experience with Euphoria
than I have (about 1 week).  Hopefully, someone will be able to find what
I'm doing wrong.  Also, there is a *severe* lack of documentation on the PI
routine itself.  This is due in part to the lazyness of the original author,
and in part to the fact that I only understand WHAT the program does, not
the underlying math theory.  Again, maybe someone can enlighten me. :)

TABLE 1
                                          Approximate Execution Time (seconds)
|---------------------------------------------------------------------------
----------------
|Language & Ver  |   100  digits   |   200  digits   |   300  digits   |
400  digits   |
|---------------------------------------------------------------------------
----------------
|  Euphoria 1.5     |        1.65       |       6.71         |        15.05
|        26.81     |
|  QBasic 1.1        |        5.72       |     22.63         |        50.92
|        90.52     |
|  QuickBasic 4.5 |        3.13       |     12.47         |        28.18
|        49.93     |
|---------------------------------------------------------------------------
----------------
|  QuickBasic 4.5 |                      |                       |
|                      |
|  (compiled exe)  |        0.72       |       2.64         |          5.98
|        10.66     |
----------------------------------------------------------------------------
---------------
NOTE:  I did not think it fair to actually include the compiled PI.BAS along
with the interpreted versions, thus the seperate section.  (notice that
QB4.5 interpreted the file nearly 2x as fast as QBasic 1.1 did?)
As you can see, however, QB4.5's ability to compile to semi-pure .exe is a
definate speed advantage.  (Binding the program with EX, to the best of my
knowledge, just results in an internal version of the program getting
attached to the EX binary, which doesnt actually produce a truely compiled
program.  Therefore,  no catagory was made for an exe form of PI.EX, since
the times stated for the interpreted version would be the same).
        That brings me to an obvious question which I won't ask, since I am
sure it has been asked by every Euphoria programmer.  (And I know the answer
goes something like <insert nasty RTFM response here>.  ;)  ).

--=====================_859198120==_
 x-mac-type="705A4950"; x-mac-creator="705A4950"

new topic     » topic index » view message » categorize

2. PI routines

James Powell writes:
>    However, there is a *minor* bug in the Euphoria version that I
> cannot quite figure out.  It seems that it does not want to properly
> calculate the last two (2 :) ) digits of PI.  ie, when calculating to 50
> digits,  PI.EX responds with:
> 3.141592653589793238462643383279502884197169399374
> but PI.BAS returns:
> 3.1415926535897932384626433832795028841971693993751

In the Basic version you say "OPTION BASE 0"
(which is the default anyway I believe). This means
that when the user asks for 50 digits, you calculate
using an array dimensioned from 0 to 50, i.e. *51*
digits. At the end you only print from 0 to 49, so
only 50 digits are displayed. The 51st digit which
may not be very accurate, is not displayed.
In the Euphoria version you calculate PI with a sequence
that is indexed from *1* to 50, i.e. only 50 digits.
You then print elements 1 to 49, i.e. only 49 digits. You'll
notice above that the Euphoria output has one less
digit displayed.

If you add 1 to the number of digits requested by
the Euphoria user, the Euphoria and QBasic programs
will have identical results.

Thanks for the interesting benchmark.

   Rob Craig
   Rapid Deployment Software

new topic     » goto parent     » topic index » view message » categorize

3. Re: PI routines

>James Powell writes:
>>    However, there is a *minor* bug in the Euphoria version that I
>> cannot quite figure out.  It seems that it does not want to properly
>> calculate the last two (2 :) ) digits of PI.  ie, when calculating to 50
>> digits,  PI.EX responds with:
>> 3.141592653589793238462643383279502884197169399374
>> but PI.BAS returns:
>> 3.1415926535897932384626433832795028841971693993751
<snip>

Robert Craig responded:
>
>In the Basic version you say "OPTION BASE 0"
>(which is the default anyway I believe). This means
>that when the user asks for 50 digits, you calculate
>using an array dimensioned from 0 to 50, i.e. *51*
>digits.

<snip>

>If you add 1 to the number of digits requested by
>the Euphoria user, the Euphoria and QBasic programs
>will have identical results.
>
>Thanks for the interesting benchmark.
>
>   Rob Craig
>   Rapid Deployment Software
>

Thanks, I tried that and it now works properly.  Also, for those interested,
the times I quoted in my benchmark were done on a 486DX2/66 with 24 megs of
ram running Caldera OpenDOS 7.01.  The task manager was not loaded, so as to
not color the times in any way.

James.

new topic     » goto parent     » topic index » view message » categorize

4. PI routines

--Message-Boundary-16328
Content-type: text/plain; charset=US-ASCII
Content-description: Information about this message.

This message contains a file prepared for transmission using the
MIME BASE64 transfer encoding scheme. If you are using Pegasus
Mail or another MIME-compliant system, you should be able to extract
it from within your mailer. If you cannot, please ask your system
administrator for help.

   ---- File information -----------
     File:  pi.ex
     Date:  29 Mar 1997, 12:39
     Size:  5278 bytes.
     Type:  Binary

--Message-Boundary-16328
Content-type: Application/Octet-stream; name=pi.ex; type=Binary

new topic     » goto parent     » topic index » view message » categorize

5. PI routines

Hello James,

           Here's something you might be interested in.
After about 20 minute's work :), I came up with this improved
version of your PI calculator. It runs about 2.5 times as fast,
bringing it up to the speed of your compiled Quick-Basic program.

Regards,
               Michael Bolin

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu