Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Nymphodora, Quad), 923 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 4 1 2 3 4
Re: file_write var array ? [Re: laz] #478135
09/11/19 17:19
09/11/19 17:19
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
<snip>

Last edited by AndrewAMD; 09/11/19 18:02. Reason: misread the output
Re: file_write var array ? [Re: AndrewAMD] #478136
09/11/19 17:39
09/11/19 17:39
Joined: Oct 2018
Posts: 72
J
JamesHH Offline
Junior Member
JamesHH  Offline
Junior Member
J

Joined: Oct 2018
Posts: 72
Umm, you've just proved my point.

Yes, var is typedef'd as double, but that's not the issue.

Your output shows that, in Zorro, var/double is behaving just like a 32-bit float:

float representation of 0.123456789012345678901234567890

That's called an MRE, not production code. Which branch do you think should execute?

Re: file_write var array ? [Re: laz] #478148
09/13/19 17:26
09/13/19 17:26
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
You can easily see with a tiny script that var behaves like a 64 bit double. But number representation and variable precision are not the same. Variables have 15 decimals, numbers written in your script have probably less.

Re: file_write var array ? [Re: Petra] #478150
09/13/19 20:18
09/13/19 20:18
Joined: Oct 2018
Posts: 72
J
JamesHH Offline
Junior Member
JamesHH  Offline
Junior Member
J

Joined: Oct 2018
Posts: 72
Originally Posted by Petra
You can easily see with a tiny script that var behaves like a 64 bit double. But number representation and variable precision are not the same. Variables have 15 decimals, numbers written in your script have probably less.


No, my script demonstrates that var/double behaves like a 32-bit precision float.

Did you see the one above where 1.00000001 == 1.0?

Here is another script showing that type "double" is 32-bit precision in Zorro:

function main()
{
double x = 0.123456789012345;

printf("\nx = %.15f", x);
}

Output:

x = 0.123456791043282

The output is the float representation of the number 0.123456789012345: float 32-bit representation of 0.123456789012345

Re: file_write var array ? [Re: laz] #478151
09/13/19 20:25
09/13/19 20:25
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
That script wont work, youre still confusing number representation with precision.

Standard test program for variable precision:

Code
void main()
{
	double d = 1000000000000000.;  // 15 zeros -> 64 bits
	d = 1. + 1./d;
	printf("\n %.15f",d);
}

laugh

Re: file_write var array ? [Re: Petra] #478152
09/13/19 22:49
09/13/19 22:49
Joined: Oct 2018
Posts: 72
J
JamesHH Offline
Junior Member
JamesHH  Offline
Junior Member
J

Joined: Oct 2018
Posts: 72
Interesting!

So why is x being set to 1.0 in the following script?

Code

function main()
{
	double x = 1.00000001;
	printf("\n %.15f", x);
}


Re: file_write var array ? [Re: Petra] #478153
09/13/19 22:59
09/13/19 22:59
Joined: Oct 2018
Posts: 72
J
JamesHH Offline
Junior Member
JamesHH  Offline
Junior Member
J

Joined: Oct 2018
Posts: 72
Oh, so you are saying that *constants* do not have the same precision as variables?

Re: file_write var array ? [Re: laz] #478155
09/14/19 08:31
09/14/19 08:31
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Numbers in scripts are interpreted as either int or float, depending on decimal point. This must be kept in mind when assigning very large or very small constants or constant expressions to a variable. You can find details in the manual under "Variables". This has nothing to do with the bit size of a double.

Re: file_write var array ? [Re: laz] #478158
09/15/19 12:17
09/15/19 12:17
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
As a workaround, you can enter a high-precision variable as a string and then parse it.

Code
#include <default.c>
void main() {
	var v = strvar("0.123456789012345678901234567890",0,0.0);
	printf("\nv: %0.30f",v);
	v *= 10000000000.;
	printf("\nv: %0.30f",v);
	printf("\ndone.");
}
/*  output:
v: 0.123456789012345680000000000000
v: 1234567890.123456700000000000000000000000
done.
*/


Here's the original script, fixed:
Code
#include <default.c>
void run() {
	string my_file = "Data\\FAA_TEST.csv";

	int  ar_used = 3;
	var my_array[100];	

	my_array[0] = strvar("1000.0001",0,0);
	my_array[1] = strvar("2000.0002",0,0);
	my_array[2] = strvar("3000.0003",0,0);

	file_delete(my_file);	
	file_write(my_file,my_array,ar_used*8);
		
	var my_read[100];

	file_read(my_file,my_read,10*8);

	int i;

	for(i=0;i<10;i++) printf("\nmy_array[%i] %f | my_read[%i] %f",i,my_array[i],i,my_read[i]);

	quit();
}
/*  OUTPUT:
	float_test compiling...........
	my_array[0] 1000.000100 | my_read[0] 1000.000100
	my_array[1] 2000.000200 | my_read[1] 2000.000200
	my_array[2] 3000.000300 | my_read[2] 3000.000300
	my_array[3] 0.000000 | my_read[3] 0.000000
	my_array[4] 0.000000 | my_read[4] 0.000000
	my_array[5] 0.000000 | my_read[5] 0.000000
	my_array[6] 0.000000 | my_read[6] 0.000000
	my_array[7] 0.000000 | my_read[7] 0.000000
	my_array[8] 0.000000 | my_read[8] 0.000000
	my_array[9] 0.000000 | my_read[9] 0.000000
	Quit
*/


Or you can write your script in VC++, so you will not need to put up with the eccentricities of the Lite-C compiler. laugh

Re: file_write var array ? [Re: AndrewAMD] #478162
09/16/19 00:32
09/16/19 00:32
Joined: Oct 2018
Posts: 72
J
JamesHH Offline
Junior Member
JamesHH  Offline
Junior Member
J

Joined: Oct 2018
Posts: 72
Thanks for the suggestions.

Yes, but this requires Zorro-S if I understood the manual. I should have Zorro-S considering how much I use it.

Page 3 of 4 1 2 3 4

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1