About floating point

Hi,

  1. I have an input like 0.02, and I check in LAMMPS it looks like 0.020000000000156. How to define exactly 0.02?

  2. How to “round” with 3 numbers or 4 numbers after floating point?

What Every Computer Scientist Should Know About Floating-Point Arithmetic:

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

You'll also find original pdf and reprints on the www.

Tomasz

What Every Computer Scientist Should Know About Floating-Point Arithmetic:

What Every Computer Scientist Should Know About Floating-Point Arithmetic

You'll also find original pdf and reprints on the www.

that document may be a little bit over the top and is primarily
addressed at "*computer* scientists" and not so much "*computational*
scientists"
the topic of floating point semantics and accuracy is often topic of
lectures at HPC workshops for computational scientists, and there
matters are presented in a much more simplified fashion. a recent
version of my lecture on the topic is posted here:

the short, short version is: a number like 0.02 simply *cannot* be
represented exactly with IEEE-754 floating point math (which is what
CPUs are using these days).

axel.