A
A
ardentum2018-03-27 12:58:13
JavaScript
ardentum, 2018-03-27 12:58:13

Why is the accuracy of calculations in float violated for numbers of a certain power of two?

Hello! Can someone explain how floating point numbers work?
An example is the following: Why do problems with precision occur for groups of numbers starting with a power of two in such a calculation? The first group starts at 16, the second at 64, and the third at 2048. I understand floats aren't guaranteed to be accurate, but why is it acting this way in this case? Just curious.
_.range(0,2050).map(i => (i + 0.99) * 100);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
res2001, 2018-03-27
@res2001

Yes, floating point numbers are not guaranteed to be accurate. Read the Wikipedia article, it is quite adequate.
Don't count money in floating numbers :)

T
tsarevfs, 2018-03-27
@tsarevfs

https://habrahabr.ru/post/112953/

M
Mercury13, 2018-03-27
@Mercury13

It is probably connected with the peculiarities of translating fractional numbers into text. I tried to repeat it in C++, nothing interesting happened. On the other hand, G++ and GRISU methods for converting fractional to text give slightly different results.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question