On Wed, Oct 28, 2015 at 10:08 AM, James K. Lowden <jklowden at schemamania.org>
wrote:

> On Fri, 23 Oct 2015 10:43:44 -0700 Scott Hess <shess at google.com> wrote:
> > You're right, any base-2 representation right of the decimal should be
> > precise to represent in base-10.  But it's the kind of thing where if
> > you find yourself counting on it, you probably made a grave error
> > earlier in your design :-).
>
> I'm either brave or naive enough to think I can still add to this
> discussion.  If we accept what you say, above, then why should
>
> >  (9.2+7.8+0+3.0+1.3+1.7)
>
> in particular present any problem?  There's no division.  Each value
> has an exact decimal representation.  I'm prepared to assert that any
> permutation of their sums also has an exact decimal representation.
> Therefore they should have an exact binary representation, too.


Of those numbers, only 0 and 3.0 have an exact binary representation:
  echo 9.2 7.8 0 3.0 1.3 1.7 | xargs -n1 -I{} printf "{} is %a\n" {}
  9.2 is 0x1.2666666666666p+3
  7.8 is 0x1.f333333333333p+2
  0 is 0x0p+0
  3.0 is 0x1.8p+1
  1.3 is 0x1.4cccccccccccdp+0
  1.7 is 0x1.b333333333333p+0

Those binary representations can be converted back into precise decimal
representations, but those decimal representations will not be the original
decimal values, because they were translated from decimal strings into
binary floating-point values and back into decimal strings.

-scott

Reply via email to