Gamestudio Links
Zorro Links
Newest Posts
Reality Check results on my strategy
by dBc. 10/11/25 06:15
Help!
by AndrewAMD. 10/08/25 19:31
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 11,816 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Jota, krishna, DrissB, James168, Ed_Love
19169 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Discrepancy between Zorro and Visual Studio results SOLVED #488918
09/21/25 13:11
09/21/25 13:11
Joined: Jan 2017
Posts: 19
Israel
D
dBc Online OP
Newbie
dBc  Online OP
Newbie
D

Joined: Jan 2017
Posts: 19
Israel
Hello,



*** UPDATE***

I made some homework and changed the question, to be straight forward.

I run the below code in both Zorro and Microsoft Visual Studio C:

Code
function main(){
	double a1 = 0.56434;
	double a2 = 0.56506;
	printf("\n %.10e", (a1-a2)/a2);
	
	double a3 = 0.58299;
        double a4 = 0.56434;
        printf("\n %.10e", (a3-a4)/a4);
}



On Zorro I got:
Quote

Zorro 2.66.3
(c) oP group Germany 2025


returns compiling........... ok

-1.2742435919e-003
3.3047445653e-002



On VC and a calculator, I got:
Quote

-1.2742009698e-03
3.3047453663e-02


It seems that Zorro used float calculation, it's not clear to me why?


Thanks
David

Last edited by dBc; Yesterday at 19:33. Reason: Clearly title
Re: Discrepancy between Zorro and Visual Studio results [Re: dBc] #488929
10/08/25 13:00
10/08/25 13:00
Joined: Jul 2000
Posts: 28,025
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,025
Frankfurt
You can easily solve that mystery by printing a bit more:

printf("\n %.10e %.10e %.10e",a1,a2,(a1-a2)/a2);

Floating point arithmetic happens on your CPU hardware, so you will always get the same result with the same numbers, no matter what compiler you use. But with slightly different numbers you get slightly different results. It's the precompiler that interprets your constants which is different. See: https://zorro-project.com/manual/en/aarray.htm

Re: Discrepancy between Zorro and Visual Studio results [Re: jcl] #488932
10/09/25 08:52
10/09/25 08:52
Joined: Jan 2017
Posts: 19
Israel
D
dBc Online OP
Newbie
dBc  Online OP
Newbie
D

Joined: Jan 2017
Posts: 19
Israel
Thank you for your reply.

It's an honor for me that a very qualified and intelligent person like you, replied to my question.

I apologize but not really understood your answer.

I read carefully the manual, and then updated the post, so the question in the top is after reading the manual.

I run this code on Microsoft Visual Studio:
Code
        double a1 = 0.56434;
        double a2 = 0.56506;
        printf("\n %.10e %.10e %.10e", a1, a2, (a1 - a2) / a2);


Please see the attached VC results

I run this code on Phyton:
Code
a1 = 5.6434e-1
a2 = 5.6506e-1

print("\n {:.10e} {:.10e} {:.10e}".format(a1, a2, (a1 - a2) / a2))


Please see the attached Python results.

I run this calculation on RStudio and got the attached file.

I run this calculation on PC's calculator and got the attached file.

I don't understand why coding with 4 different languages/application provide the same results, but Zorro result differs?

Thanks
David

Attached Files Screenshot (4).pngScreenshot (3).pngScreenshot (5).pngScreenshot (1).png
Re: Discrepancy between Zorro and Visual Studio results [Re: dBc] #488933
10/09/25 16:33
10/09/25 16:33
Joined: Feb 2017
Posts: 1,808
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,808
Chicago
It's because you wrote your Zorro script in Lite-C.
Quote
numbers or constant expressions containing a decimal point (123.456) are treated as float with 7 significant digits.
https://zorro-project.com/manual/en/aarray.htm

Zorro also supports C++ scripting, where you will not have to deal with the eccentricities of Lite-C and its compiler.
https://zorro-project.com/manual/en/dlls.htm

Re: Discrepancy between Zorro and Visual Studio results [Re: AndrewAMD] #488934
10/09/25 16:48
10/09/25 16:48
Joined: Jan 2017
Posts: 19
Israel
D
dBc Online OP
Newbie
dBc  Online OP
Newbie
D

Joined: Jan 2017
Posts: 19
Israel
Thank you AndrewAMD, I'll try run it with C++

David

Re: Discrepancy between Zorro and Visual Studio results [Re: dBc] #488935
Yesterday at 19:33
Yesterday at 19:33
Joined: Jan 2017
Posts: 19
Israel
D
dBc Online OP
Newbie
dBc  Online OP
Newbie
D

Joined: Jan 2017
Posts: 19
Israel
I found the problem

The manual says:

Quote

Due to the 7 digit limit, var X = 123456789.0; would in fact set X to 123456792.0; but var X = 123456789; sets it to 123456789.0 since int has 10 significant digits.


So, I changed the code to:
Code
		double a1 = 56434;
		double a2 = 56506;
		printf("\n %.10e %.10e %.10e",a1,a2,(a1-a2)/a2);



Got the desired results:

Quote


returns compiling............ ok

5.6434000000e+004 5.6506000000e+004 -1.2742009698e-003



Thanks
David


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1