|
Re: file_write var array ?
[Re: laz]
#478135
09/11/19 17:19
09/11/19 17:19
|
Joined: Feb 2017
Posts: 1,726 Chicago
AndrewAMD
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,726
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
JamesHH
Junior Member
|
Junior Member
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.123456789012345678901234567890That's called an MRE, not production code. Which branch do you think should execute?
|
|
|
Re: file_write var array ?
[Re: Petra]
#478150
09/13/19 20:18
09/13/19 20:18
|
Joined: Oct 2018
Posts: 72
JamesHH
Junior Member
|
Junior Member
Joined: Oct 2018
Posts: 72
|
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: Petra]
#478152
09/13/19 22:49
09/13/19 22:49
|
Joined: Oct 2018
Posts: 72
JamesHH
Junior Member
|
Junior Member
Joined: Oct 2018
Posts: 72
|
Interesting! So why is x being set to 1.0 in the following script?
function main()
{
double x = 1.00000001;
printf("\n %.15f", x);
}
|
|
|
Re: file_write var array ?
[Re: laz]
#478158
09/15/19 12:17
09/15/19 12:17
|
Joined: Feb 2017
Posts: 1,726 Chicago
AndrewAMD
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,726
Chicago
|
As a workaround, you can enter a high-precision variable as a string and then parse it. #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: #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.
|
|
|
|