exponential growth problem with showing 19 digits

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

exponential growth problem with showing 19 digits

Post by ROBROS »

Hi friends,
surely most of you if not all know the story of the grains of rice on a chessboard. On the first field you put one grain, on the second field the first field is doubled, on the third field the second field is doubled and so on up to field 64. I have written a small program to demonstrate every step in this calculation. It works fine, but on the 64th field the result is unexpected: the 6 most right digits should be "775808" but it turns out they are :"776000".
I don't know why that happens. 19 digits should be possible, the number on field 63 also has 19 digits, which are shown exactly.

I have attached a zip file with all files necessary and a screenshot. I use the 32 bit version of hmg as you can see on the screenshot. Would a 64 bit version show the complete right 19 digits? Who can explain?

Thx Robert
Attachments
chessboard.7z
(2.56 MiB) Downloaded 105 times
Last edited by ROBROS on Wed Dec 23, 2020 10:43 am, edited 2 times in total.
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: exponentional growth problem with showing 19 digits

Post by Claudio Ricardo »

Hi...
Try at the begin of main.prg

Set Exact On
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: exponentional growth problem with showing 19 digits

Post by ROBROS »

Hi Claudio,
thank you for answering,
set exact on does not solve the problem.

Robert
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: exponentional growth problem with showing 19 digits

Post by Claudio Ricardo »

Tonight I will check your code and if I find the problem I post, now I am working XD
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: exponential growth problem with showing 19 digits

Post by Claudio Ricardo »

Hi...
Your code no have error...
I make other prg with some result...
Obviously it is a limitation, the result in the variable and the Browse is different from the one saved in the DBF.
Below I only show the result of multiplying the result of 63 by 2 and it also gives wrong (round)
We'll have to look at the Harbor documentation ...

Hola...
Tu código no tiene errores...
Hice otro programa para probar y da el mismo resultado...
Evidentemente es una limitación, el resultado en la variable y el Browse es diferente al que guarda en la DBF.
Abajo sólo muestro el resultado de multiplicar el resultado de 63 por 2 y también da equivocado (redondea)
Habrá que buscar en la documentación de Harbour...
Attachments
Exponente.zip
(1.46 MiB) Downloaded 99 times
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: exponential growth problem with showing 19 digits

Post by ROBROS »

Hi Claudio, thx again for your effort.
martingz
Posts: 401
Joined: Wed Nov 18, 2009 11:14 pm
Location: Mexico

Re: exponential growth problem with showing 19 digits

Post by martingz »

in HMG 64 bits it gives wrong, in excel also
in clipper documentation 18 digits max
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: exponential growth problem with showing 19 digits

Post by ROBROS »

But in field 63 you see 19 digits, could it be it is dependent on the numbers value?
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: exponential growth problem with showing 19 digits

Post by ROBROS »

My son, a Dr. rer. nat. explained it with the fact that calculation is done on a binary base and in field 64 I get an overflow when converting binary to decimal.
Thank you for all your answers.
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: exponential growth problem with showing 19 digits

Post by ROBROS »

ROBROS wrote: Wed Dec 23, 2020 7:01 pm My son, a Dr. rer. nat. explained it with the fact that calculation is done on a binary base and in field 64 I get an overflow when converting from binary to decimal is done.
Thank you for all your answers.
Post Reply