3 ms·
> and to have your output round-trip Unless you're simply talking about round-trip within the application itself, that's not possible.
by jancsika 8y ago
> and to have your output round-trip
Unless you're simply talking about round-trip within the application itself, that's not possible.
- tlb 8y agoIt is possible, and most reasonable format systems guarantee it. Javascript guarantees that parseFloat(x.toString()) === x for any fp number x. The same extends to JSON formatting. Python guarantees that eval(str(x)) == x.
- jancsika 8y agoThat's because Javascript doesn't print out the shortest possible output. OP's requirement is that the output for 0.1 + 0.11 is displayed as 0.21, and that the output survives a round-trip. Your example satisfies the latter but not the former.
- kkylin 8y agoAnother example, more specialized than the others given, is MIT Scheme: IIRC it guarantees that when you READ back a float written by WRITE, you get the same float back, bit for bit.