<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Mar 13, 2017 at 12:57 PM Eric Wieser <<a href="mailto:wieser.eric%2Bnumpy@gmail.com">wieser.eric+numpy@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> `float(repr(a)) == a` is guaranteed for Python `float`<br class="gmail_msg">
<br class="gmail_msg">
And `np.float16(repr(a)) == a` is guaranteed for `np.float16`(and the same<br class="gmail_msg">
is true up to `float128`, which can be platform-dependent). Your code<br class="gmail_msg">
doesn't work because you're deserializing to a higher precision format than<br class="gmail_msg">
you serialized to.<br class="gmail_msg"></blockquote><div> </div><div class="inbox-inbox-uyb8Gf" style="color:rgb(33,33,33);font-size:13px"><div><div class="inbox-inbox-F3hlO"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">I would hesitate to make this guarantee - certainly for old versions of numpy, np.float128(repr(x))!=x in many cases. I submitted a patch, now accepted, that probably accomplishes this on most systems (in fact this is now in the test suite) but if you are using a version of numpy that is a couple of years old, there is no way to convert long doubles to human-readable or back that doesn't lose precision.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">To repeat: only in recent versions of numpy can long doubles be converted to human-readable and back without passing through doubles. It is still not possible to use % or format() on them without discarding all precision beyond doubles. If you actually need long doubles (and if you don't, why use them?) make sure your application includes a test for this ability. I recommend checking repr(1+np.finfo(np.longdouble).eps).</div><div class="gmail_msg"><br></div><div class="gmail_msg">Anne</div></div></div></div></div></div><div class="inbox-inbox-uyb8Gf" style="color:rgb(33,33,33);font-size:13px"><div class="inbox-inbox-F3hlO"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div></div></div></div></div><div><span style="color:rgb(33,33,33);font-size:13px">P.S. You can write (I have) a short piece of cython code that will reliably repr and back long doubles, but on old versions of numpy it's just not possible from within python. -A </span> </div></div></div>