Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4
Floating point arithmetic is not accurate. Internally variables may not be in the form we are familiar with. Consider 0.1. To form the binary representation, we must express this as a power of two. But no sum of powers of two add up to 0.1. We can only represent numbers nearby to 0.1 like 0.10000000149011611... 625. This error is increased when further arithmetic is performed on these numbers. The solution is to check if the absolute difference of the numbers being compared is within an acceptable limit, like 0.000005. Those numbers tend to be equal. For more information, check these posts: https://www.sololearn.com/discuss/1012768/?ref=app https://www.sololearn.com/discuss/1424039/?ref=app https://www.sololearn.com/discuss/1065886/?ref=app https://www.sololearn.com/discuss/1392626/?ref=app https://www.sololearn.com/discuss/1606645/?ref=app
19th Mar 2019, 6:47 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar