Nodal coordinates are not precise

Moderator: GiD Team

Post Reply
Daniel
Posts: 20
Joined: Fri Feb 03, 2023 4:08 pm

Nodal coordinates are not precise

Post 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.
Daniel
Posts: 20
Joined: Fri Feb 03, 2023 4:08 pm

Re: Nodal coordinates are not precise

Post by Daniel »

Like, if I insert 0.10, the .dat file shows

1.000000000000000418e-01

And this is not 0.10.
User avatar
escolano
Posts: 1918
Joined: Sun Sep 05, 1982 10:51 pm

Re: Nodal coordinates are not precise

Post 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)
Post Reply