Hi Brent 'Dax' Royal-Gordon,

>> option. Yet the Leibniz summation for PI 
>> <http://www.parrotcode.org/examples/>
>> still appears to be performing its calculations using single floats and
>> continues to print 3.141591.
> 
> Parrot usually uses double as its floating-point type.  The problem is
> probably with the precision of 'print N0'; try using the 'sprintf'
> opcode and printing the resulting string instead.

Many thanks for the tip!

.sub _main
        set     N1, 1
        set     N2, 1000000
        set     N3, 0
        set     N4, 0
        set     I1, 0
REDO:   div     N4, 1.0, N1
        if      I1, SUB
        add     N3, N4, N3
        set     I1, 1
        branch  END
SUB:    sub     N3, N3, N4
        set     I1, 0
END:    add     N1, 2
        le      N1, N2, REDO
DONE:   mul     N3, N3, 4.0

        new     P0, .PerlArray
        set     P0, 1
        set     P0[0], N3
        sprintf S0, "PI is (very) approximately: %.20f\n", P0
        print   S0
        end
.end

On a windows binary I downloaded the precision is indeed double (~16
decimal places). With my current Linux binary it's extreme (here's 60
decimal places):

PI is (very) approximately: 
3.141590653589694692726652647252194583415985107421875000000000

This may be the long double version that I compiled :-)

Thanks again,
Adam

Reply via email to