exponential growth problem with showing 19 digits
Moderator: Rathinagiri
exponential growth problem with showing 19 digits
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
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.
- 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
Hi...
Try at the begin of main.prg
Set Exact On
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
WhatsApp / Telegram: +54 911-63016162
Re: exponentional growth problem with showing 19 digits
Hi Claudio,
thank you for answering,
set exact on does not solve the problem.
Robert
thank you for answering,
set exact on does not solve the problem.
Robert
- 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
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
WhatsApp / Telegram: +54 911-63016162
- 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
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...
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
WhatsApp / Telegram: +54 911-63016162
Re: exponential growth problem with showing 19 digits
Hi Claudio, thx again for your effort.
Re: exponential growth problem with showing 19 digits
in HMG 64 bits it gives wrong, in excel also
in clipper documentation 18 digits max
in clipper documentation 18 digits max
Re: exponential growth problem with showing 19 digits
But in field 63 you see 19 digits, could it be it is dependent on the numbers value?
Re: exponential growth problem with showing 19 digits
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.
Thank you for all your answers.