Page 1 of 1

Nodal coordinates are not precise

Posted: Tue Mar 07, 2023 3:45 pm
by Daniel
Hi everyone,

good morning.

I am having a issue with nodal coodinates precisio. After inserting them with

Utilities -> Tools -> Coordinates window (and then geometry -> create -> point)

the coordinates in the .dat file are not precise as I inserted previous.

I am using the following configuration to write the .dat file:

customlib::WriteString "Node x (m) y (m) z (m)"
customlib::WriteCoordinates "%d %.18e %.18e %.18e\n"

If anyone could help me will be great.

Re: Nodal coordinates are not precise

Posted: Wed Mar 08, 2023 2:25 pm
by Daniel
Like, if I insert 0.10, the .dat file shows

1.000000000000000418e-01

And this is not 0.10.

Re: Nodal coordinates are not precise

Posted: Thu Mar 09, 2023 1:36 pm
by escolano
Your are confusing concepts
Your coordinates are as precise as the precision %.18e that you set
(off course precision is finite, a double number is handled with 8 Bytes)
your number 0.1
written as an ASCII string
1.000000000000000418e-01
has very good precision, and for computers probably is ok
but for a human looks ugly and he expects to see "0.1"

Computers really works internally with binary numbers, not decimal numbers as humans, and with finite precision (4 Bytes or float, 8 Bytes for double,...)
and unfortunately the number 0.1 decimal has a finite representation in this base 10, but in binary (base 2) representation become a infinite periodic series, then is impossible to be exactly represented in any computer
https://www.educative.io/answers/why-do ... ting-point
always will be truncated with some precision.

Off course is possible to do format tricks with 1.000000000000000418e-01 to be printed as a string with the letters
"0.1"
but usually these tricks are problematic (e.g. a "format %.1f" of 1.000000000000000418e-01 will print the string 0.1 but will truncate the precision to 1 for other numbers)