From: Brian P. <bri...@in...> - 2006-09-20 22:00:24
|
Hi Michael, Not sure I follow you... isn't "0.1" decimal? BTW that http://mail.python.org/pipermail/python-dev/2004-March/043742.html discussion ends on this note: "> Remember that every binary floating-point number has an exact decimal > representation (though the reverse, of course, is not true). Yup." So no, you can't always make the roundtrip without introducing error. More importantly, you can't always read an ASCII decimal value and compute with it without introducing error. And, as I mentioned before, that decimal->binary conversion isn't cheap. - Brian > -----Original Message----- > From: psi...@li... > [mailto:psi...@li...] On > Behalf Of Coleman, Michael > Sent: Wednesday, September 20, 2006 2:44 PM > To: bri...@in...; psi...@li... > Subject: Re: [Psidev-ms-dev] Why base64? > > > Brian Pratt: > > > ...with properly implemented numeric I/O > > > routines (in libc), you can have a 1-1 mapping between the > > > internal and > > > ASCII representation, so that it is possible to round trip without > > > introducing error. > > > > Well, no, but this is something a lot of folks don't realize. > > For (a previously cited by Randy) example consider "0.1" - see > > http://www.yoda.arachsys.com/csharp/floatingpoint.html for an > > explanation. > > I think we're talking about two different things. As you > say, 0.1 does > not have an exact IEEE 754 representation. I'm talking about > conversion > between decimal and IEEE 754. Intuitively, for each IEEE 754 double, > there are a set of decimal numbers closer to it than to any other > double. Of that set, one will have the shortest decimal > representation, > after all trailing zeros have been truncated. (There may be > two, which > is handled by round-to-even.) This representation can in turn be > uniquely mapped back to the double. I think that something > like this is > specified by IEEE 754, but I can't find an exact reference on the web. > Java specifies this: > > > http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html# > toString(d > ouble) > > and here's a discussion that seems to reference it > > > http://mail.python.org/pipermail/python-dev/2004-March/043742.html > > I probably don't have the details exactly right, but I > believe the basic > idea is correct. The effect of this is that it is possible to use a > decimal representation without introducing any error. My preference, > though, would still be to round away the noise digits. > > Mike > > > > -------------------------------------------------------------- > ----------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the > chance to share your > opinions on IT & business topics through brief surveys -- and > earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge > &CID=DEVDEV > _______________________________________________ > Psidev-ms-dev mailing list > Psi...@li... > https://lists.sourceforge.net/lists/listinfo/psidev-ms-dev > |