R
R
Rienopely2015-10-10 07:37:52
Java
Rienopely, 2015-10-10 07:37:52

Why would 0.1 + 0.1 + 0.1 - 0.3 be a very large number?

If you take a double in java, it will be 5.551115123125783E-17, and if it's a float, then 0. In python, float also produces a miracle number. I know this is a noob question, but please help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin, 2015-10-10
@rienopely

at the end of the number 5.551115123125783E-17 there is E-17, this shows the order of the number, i.e. such a number is equal to 0.000000000000055111512, this happens because it is impossible to accurately represent which lib number without error with the float and double types, for example, the same 0.1 will be represented as 0.10000000003

R
Rsa97, 2015-10-10
@Rsa97

habrahabr.ru/post/112953

T
Taxist410, 2015-10-10
@Taksist410

it's a rounding error

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question