On Fri, Jun 27, 2008 at 2:54 PM, Mark Dickinson <dickinsm at gmail.com> wrote: > On Fri, Jun 27, 2008 at 8:02 PM, Guido van Rossum <guido at python.org> wrote: >> Now that I've learned about the hex float format supported by C++ and >> Java, I wonder if it wouldn't be better to support conversion to and >> from that format and nothing else. >> >> E.g. >> >>>>> math.tohex(3.14) >> '0x1.91eb851eb851fp+1' >>>>> math.fromhex('0x1.91eb851eb851fp+1') >> 3.1400000000000001 > > This would certainly be enough for me, though I think there's still > some educational value in having binary output available. But > that's just a matter of substituting a four-bit binary string for > each hexadecimal digit (or learning to read hexadecimal as > though it were binary). If it's educational it can be left as an exercise for the reader. :-) > In fromhex, what would be done with a string that gives more > hex digits than the machine precision can support? An obvious > answer is just to round to the nearest float, but since part of the > point of hex floats is having a way to specify a given value > *exactly*, it might make more sense to raise an exception > rather than changing the value by rounding it. Whatever Java and C99 do. -- --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4