How to convert this code from Wikipedia?

Just starting out? Need help? Post your questions and find answers here.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

How to convert this code from Wikipedia?

Post 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? :)
infratec
Always Here
Always Here
Posts: 7663
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to convert this code from Wikipedia?

Post 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
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: How to convert this code from Wikipedia?

Post 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! :)
infratec
Always Here
Always Here
Posts: 7663
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to convert this code from Wikipedia?

Post by infratec »

Maybe one of our russian members can translate it.
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: How to convert this code from Wikipedia?

Post 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
Former user of pirated PB.
Now registered user :].
infratec
Always Here
Always Here
Posts: 7663
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to convert this code from Wikipedia?

Post by infratec »

Thanks Michael,

but not what I expected :cry:

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

Bernd
Post Reply