bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] Is od broken?


From: Jim Meyering
Subject: Re: [OT] Is od broken?
Date: Fri, 13 Jun 2008 23:29:24 +0200

Eric Blake <address@hidden> wrote:
...
> But POSIX is clear that FLT_DIG is rounded down (unless your radix is a power
> of 10), to cover the decimal-binary-decimal round trip, whereas DECIMAL_DIG is
> rounded up, to cover the binary-decimal-binary round trip.  In the case of od,
> we want the algorithm of DECIMAL_DIG if we are to guarantee uniqueness.  And
> notice that simply doing FLT_DIG+1 is STILL insufficient, as shown by this 
> test
> case of the four adjacent floats 123456776.0f to 123456800.0f:
>
> $ src/od -tfFx1x4 blah
> 0000000 -1.2345678e+08 -1.2345678e+08 -1.2345679e+08 -1.2345680e+08
>          a1  79  eb  cc  a2  79  eb  cc  a3 79  eb cc  a4 79  eb cc
>               cceb79a1       cceb79a2       cceb79a3       cceb79a4
> 0000020

Good example.

> In order to safely go binary-decimal-binary, the unique decimal representation
> of 0xcceb79a2 as an IEEE single-precision float MUST be -1.23456784e+08, or
> FLT_DIG+2 bytes of precision.
>
> So, which is better, patching the code to attempt to unambiguously print all
> floats, or updating the documentation to make it clear that memory
> representation padding, floating point rounding, and NaNs cause inaccuracies?

A combination might be best, unless you fix it all at once.
If you'd like to improve parts that'd be great,
and in the mean time warn that there are inaccuracies is
the to-be fixed (or infeasible to fix) areas.

...
> OK, I'll keep them as separate commits.  Bo inspired me, and I finally figured
> out how to use repo.or.cz.  Now you can do:
> git fetch git://repo.or.cz/coreutils/ericb.git refs/heads/od
>
> to see my patch series.

Thanks!
I've applied all of that.
The first three were shoe-ins.
Nice elimination of duplication with the function-definition macro.
It offended my sensibilities ;-) to amend #4 and #5 to use TABs
consistently for indentation (you know I now prefer all-space
indentation in new files -- too bad we have to live with preexisting code).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]