Page 1 of 1

How to convert this code from Wikipedia?

Posted: Sun Feb 21, 2016 11:49 am
by Dude
I saw this image on Wikipedia:

Image

I tried to convert it to PureBasic for fun:

Code: Select all

a.f=1.0000001
b.f=a

For i=1 To 27
  a=a*a
  b=Pow(b,2) ; Wrong operator?
Next i

Debug a ; 8850397.0 (expected 568044)
Debug b ; 8850397.0 (expected 1202420)
But it doesn't show the same results. :(

I'd have thought the "a" variable value would be correct at least, but it's not.

And I'm not even sure what the symbol is doing for the "b" variable on line 25?

Can someone make the results match the Wikipedia pic? :)

Re: How to convert this code from Wikipedia?

Posted: Sun Feb 21, 2016 12:24 pm
by infratec
Hi,

if you can see on the picture, they want to show that the calculation is wrong.
Because both results should be (at least) identical.

If you use the windows calculator the result is:
674530,4707410845593826891780296

If you use .f in PB the result is
8850397.0
8850397.0

If you use .d in PB the result is
674530.47552178754
674530.47552178754

Again a question of accuracy.

You can only have the same result like in the picture if you implement faulty PB routines :mrgreen:
(But they look Ok compared to the windows calculator :D )

Bernd

Re: How to convert this code from Wikipedia?

Posted: Sun Feb 21, 2016 12:34 pm
by Dude
infratec wrote:if you can see on the picture, they want to show that the calculation is wrong.
So the result they're showing is a bug? LOL! I had no idea because I can't read the language. Thanks for explaining it, then! :)

Re: How to convert this code from Wikipedia?

Posted: Sun Feb 21, 2016 1:34 pm
by infratec
Maybe one of our russian members can translate it.

Re: How to convert this code from Wikipedia?

Posted: Mon Feb 22, 2016 9:59 am
by Korolev Michael
BASIC DVK
DO YOU NEED EXTENDED FUNCTIONS? 1
HIGHSPEED DEVICES? 1
SETUP EXTERNAL FUNCTION? 1
RAM? 48
WAIT
... some code ...

LAST TWO STRINGS:
STOP AT STRING 35
WAIT

Re: How to convert this code from Wikipedia?

Posted: Mon Feb 22, 2016 10:02 am
by infratec
Thanks Michael,

but not what I expected :cry:

I exected that there is written: example for wrong calculation
Or something similar.

Bernd