[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 3/3] Add test suite for json marshalling
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH 3/3] Add test suite for json marshalling |
Date: |
Wed, 18 Nov 2009 11:48:03 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
Jamie Lokier <address@hidden> writes:
> Anthony Liguori wrote:
>> After checking that we can demarshal, marshal again and compared to
>> the expected decoded value. This doesn't work so well for floats
>> because they cannot be accurately represented in decimal but we try
>> our best.
>
> Good sprintf/scanf/strtod implementations do guarantee that what's
> printed and then parsed gets back the same floating point value, as
> long as you have printed sufficient decimal digits.
>
> I'm not sure if FLT_DIG/DLB_DIG are the right number of digits,
> though. Glibc's documentation of those is confusing and they might
> mean something a little different.
>
> -- Jamie
Yes, conversion fp <-> decimal with sufficient precision can be made
exact. However, it's non-trivial[1], and thus neither IEEE-754 nor ISO
C require it. IIRC, GNU libc makes it exact.
No, FLT_DIG/DBL_DIG is not sufficient precision. You need 7 decimal
digits for IEEE single, 17 for IEEE double[2]. FLT_DIG is 6 and DBL_DIG
is 15 on my system.
An alternative to all that ingenuity is C99's hexadecimal format.
[1] Steele & White: How to print floating-point numbers accurately
http://portal.acm.org/citation.cfm?id=93559
Clinger: How to Read Floating Point Numbers Accurately,
http://portal.acm.org/citation.cfm?id=93557
[2] http://docs.sun.com/source/806-3568/ncg_goldberg.html#1251