C
C
Chipu2017-01-24 19:19:53
Programming
Chipu, 2017-01-24 19:19:53

Double does not output 0, how to fix?

74b8ffc5cfb14e5eb833cd580717c066.jpg
This is what 0 looks like ( 1.58871e-10)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Rsa97, 2017-01-24
@Rsa97

What makes you think it's zero? This is exactly 1.58871 * 10 -10
Arithmetic operations with real numbers on a computer are performed with a certain error, and this is exactly how it manifests itself.

E
evgeniy_lm, 2017-01-24
@evgeniy_lm

No way. For real numbers, the value 0 does not exist.
To work with real numbers, it is necessary to introduce the concept of error. then
e = 0.0000001;
........................
if Abs(A - B) < e then ............

C
Chipu, 2017-01-24
@Chipu

69086aa132764b609df0166b4e0fafc2.jpg
Here is the code itself, how can I fix it then?

X
x67, 2017-01-25
@x67

это норма. Тут объяснили, почему так. Только никто не удосужился посоветовать самое простое решение:
Используйте форматированный вывод, например так:
для cout тоже есть форматированный вывод, если принтф не устраивает

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question