From: Juergen Strobel Date: 2006-07-12T01:56:09+09:00 Subject: Re: Marshal's handling of floats --fUYQa+Pmc3FrFX/N Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jul 10, 2006 at 11:26:25AM +0900, M. Edward (Ed) Borasky wrote: > A couple of questions: >=20 > 1. How does XML handle floats? Not at all, or however you like to. XML can be used to define your own formats, it just isn't concerned with storing floats per se. > 2. How does YAML handle floats? Human readable decimal "scientific" format. Space inefficient, maybe slightly inexact, but very portable. irb(main):002:0> (1.0/3).to_yaml =3D> "--- 0.333333333333333\n" irb(main):006:0> (10.0**20/3).to_yaml =3D> "--- 3.33333333333333e+19\n" > 3. What is the format of a float when dumped using Marshal? irb(main):013:0> Marshal.dump(1.0/3) =3D> "\004\010f\e0.33333333333333331\000UU" irb(main):014:0> Marshal.dump(10.0**20/3) =3D> "\004\010f\0363.3333333333333332e+19\000\020U" This could be changed in 1.9, maybe keeping some backwards compatibilty in Marshal.load for the old format. > My recommendation would be to dump floats as the hexadecimal > representation of IEEE 64-bit formatted numbers. This is "almost > universal" and occupies only 16 bytes. The alternative, dumping them in > decimal in some "scientific" notation, takes more bytes and loses small, > but noticeable, accuracy. Moreover, it does not capture IEEE's "Inf" and > "NaN" values, which are very much part of the semantics and syntax of > modern numeric processing. >=20 > Non-IEEE architectures are very much the exception rather than the rule, > and they can be expected to dump IEEE hex and read IEEE hex as a penalty > for not adopting the standard. :) I think that's reasonable. Note that legacy machines don't need to implement full IEEE operations, just reading and writing. -J=FCrgen --=20 The box said it requires Windows 95 or better so I installed Linux --fUYQa+Pmc3FrFX/N Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iQEVAwUBRLPYIPy64gyiEfXtAQKjHwf/eHRKhbjZqTdevVnhbdX3ns/w7PzK/vVS Iwt0mn08zPnLVCRpQGEM3JKcck95/BfFvQITB0MVzS85tpXRAQtr7yKOBU3JXXeA NrExi7KFuS6sn58clSCN4Ei0xNZOpfTK3YJpW75NlWcLoC/9GZPuvannHo8TV1zN aSIdOMfNsduun/7d3SuRtqsgrq/zZR8kpWwPaDpWJS20ePNRtbj9SExplKCIdVBR KzXzLrcehtGicJOV6nmQV2TqwQgfY2gD3MwwQm8ygvrwIdoecxjufxsAL2XJFReu Voggxt96AEpgjcHMimwnP/FIfQD2Fjmxf+rOv/DGecWfkpfxlktD5A== =LitI -----END PGP SIGNATURE----- --fUYQa+Pmc3FrFX/N--