<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:Arial,Helvetica,sans-serif">On Wed, May 5, 2021 at 5:58 PM Themba Jonga <<a href="mailto:themba.jonga@gmail.com">themba.jonga@gmail.com</a>> wrote:</span><br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi All<div><br></div><div>I have the following situation  which I am trying to understand 

(screenshot below)

;</div><div><ul><li>The float N has a number of digits after the decimal point. However when converted to a list N's value is reduced, albeit by a miniscule amount.</li><li>The contrary is true for the float P which has its' value increased, also by a tiny amount.</li></ul><div>Is there any way to obtain a float_to_list() result which is the exact same as the original float, where the float variable has an arbitrary number of decimal places?</div></div><div><br></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Floating point numbers are inexact. They use this slight lack of precision as a means by which computations with them become very fast (because you have efficient implementations in hardware). However, it means your numbers as you enter them are slightly off. The numbers you entered are not representable in the underlying (bit)-representation, so a number close to the number you entered is chosen, and it is hoped that rounded to fewer decimal places will account for the inconsistency.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">The classic document about IEEE754 floating point arithmetic is this: <a href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html">https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html</a> -- but it isn't the most digestible document out there.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">A far more approachable guide is: <a href="https://floating-point-gui.de/">https://floating-point-gui.de/</a> -- but of course that might leave out some details you'd like to know.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">If you want the background Knuth's "The Art of Computer Programming Vol 2 - Seminumerical Algorithms" is one of the best expositions I've read on how they work.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">If you want the hardware-centric view, look up books by Hennesey & Patterson.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">As a general advice: getting some familiarity with floating point numbers is always good. Both in Erlang and other languages.</div><br></div></div></div>