Gamestudio Links
Zorro Links
Newest Posts
Accessing time series in TMF
by AndrewAMD. 10/23/19 20:16
priceClose() in TMF
by AndrewAMD. 10/23/19 20:11
ZeroMQ
by felixfx. 10/23/19 20:04
Issue with Starter Window
by txesmi. 10/23/19 09:22
Accessing All Historical Price Data
by JohnJits. 10/22/19 22:37
file_write var array ?
by laz. 10/22/19 16:00
SAV_STATS
by MatPed. 10/22/19 13:57
Instrument Price Zorro Chart
by jcl. 10/22/19 10:39
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
7 registered members (Dooley, AndrewAMD, Uhrwerk, Zheka, felixfx, kvm, 1 invisible), 465 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Bolle, VillageTalkies, line7, Shutch, Clifford_B
18311 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: 776
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 776
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: 40
J
JamesHH Offline
Newbie
JamesHH  Offline
Newbie
J

Joined: Oct 2018
Posts: 40
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: 253
Austria
Petra Offline
Member
Petra  Offline
Member

Joined: Apr 2008
Posts: 253
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: 40
J
JamesHH Offline
Newbie
JamesHH  Offline
Newbie
J

Joined: Oct 2018
Posts: 40
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: 253
Austria
Petra Offline
Member
Petra  Offline
Member

Joined: Apr 2008
Posts: 253
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: 40
J
JamesHH Offline
Newbie
JamesHH  Offline
Newbie
J

Joined: Oct 2018
Posts: 40
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: 40
J
JamesHH Offline
Newbie
JamesHH  Offline
Newbie
J

Joined: Oct 2018
Posts: 40
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,033
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,033
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: 776
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 776
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: 40
J
JamesHH Offline
Newbie
JamesHH  Offline
Newbie
J

Joined: Oct 2018
Posts: 40
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

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1