Guys, I'm really sorry - but I still need help with that crazy...

I read all the links (and much more):

https://en.wikipedia.org/wiki/Floating-point_arithmetic
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=467836
https://zorro-project.com/manual/en/aarray.htm
https://zorro-project.com/manual/en/format.htm

Code
var t1 = 0.1;

file_append(tfn,strf("%i,%.14f,%.14f,%.14f\n",Bar,t1,(var)t1,(double)t1),0);

result: 10,0.10000000149012,0.10000000149012,0.10000000149012

https://zorro-project.com/manual/en/aarray.htm
Type double, var | Size (bytes) 8 | Digits ~14

http://www.binaryconvert.com/result_float.html?decimal=048046049 | float(.1) | 0.100000001490116119384765625
http://www.binaryconvert.com/result_double.html?decimal=048046049 | double(.1) | 0.1000000000000000055511151231257827021181583404541015625

Why does file_append/strf write var/double as floats?

Quote
As the printf class of functions are variadic (denoted by the elipsis „…“ in the function signature) the default argument promotions take place. Finally the call printf("float = %f\n", f) will after promotion look like printf("float = %f\n", (double)f) and printf can safely assume that every %f, %g, and %e denotes a parameter of type double. https://blogs.fau.de/wittmann/2013/11/c-default-argument-promotions/

Why does printf print doubles as a float?

"%f Floating-point number (var, double) " https://zorro-project.com/manual/en/format.htm

"The printf function does not automatically promote float to double." https://manual.zorro-project.com/printf.htm

But double to float?
Quote
The %f format specifier for the printf/scanf class of functions denotes a variable of type float which consumes 32 bits. In the example above d is of type double which uses 64 bits and actually requires %lf. The provided argument d (64 bits) would be interpreted as a variable of type float (32 bits). https://blogs.fau.de/wittmann/2013/11/c-default-argument-promotions/

%lf does not exist in clite or does it?

Quote
Rounding errors occur when a number can’t be stored precisely. This can happen even with simple numbers, like 0.1. Therefore, rounding errors can, and do, happen all the time.
A corollary of this rule is: never use floating point numbers for financial or currency data. https://www.learncpp.com/cpp-tutorial/floating-point-numbers

I'm clearly missing something here and i don't get it...

Many thanks!

Last edited by laz; 08/29/19 22:56.