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 :-).

-scott


On Fri, Oct 23, 2015 at 10:40 AM, Alessandro Marzocchi <
alessandro.marzocchi at gmail.com> wrote:

> Sorry, i replied to wrong Scott Hess... mine was meant to be a reply to his
> message...
> " Internally, they are base-2 scientific notation,
> so asking for more significant digits in the base-10 representation won't
> help - base-10 fractional numbers cannot always be represented precisely in
> base-2, ALSO base-2 fractional numbers cannot always be represented
> precisely in base-10".
> Sorry for my error.
> Il 23/ott/2015 19:18, "Scott Robison" <scott at casaderobison.com> ha
> scritto:
>
> On Fri, Oct 23, 2015 at 10:45 AM, Alessandro Marzocchi <
> alessandro.marzocchi at gmail.com> wrote:
>
> > Scott.... actually all base2 fractions are rapresentable as base10
> > fractions... 10 is divisable by 2.
> > As for Richard.... try to think about this... computer does 2 base
> > calculations as we usually do calculation in base 10. But the same would
> > happend to us when talking about different bases..
> > Let's say we want to add 3 times 20 minutes (expressed in decimal of
> hours
> > up to 6th digit). 0h20' is 0.333333 hours . If you multiply that for 3
> you
> > get 0.999999.. not 1 as you expect. The
> >
>
> Yes, they are. What did I write that leads you to believe I don't
> understand that? Or are you addressing a different Scott (as there are
> three in this conversation)? I'm not upset or angry or demanding
> satisfaction, just trying to understand where my commentary went wrong and
> if I need to correct anything for the record.
>
> When I say floating point calculations are "inexact" what I mean is
> "potentially inexact" because conversion from decimal in source code to
> binary floating point in memory is potentially inexact, the arithmetic
> performed will potentially involve rounding of some form, and the final
> conversion back from binary floating point to decimal representation for
> humans can only work with what is left over after those previous potential
> approximations.
>
>
> > Il 23/ott/2015 18:31, "Scott Robison" <scott at casaderobison.com> ha
> > scritto:
> >
> > > On Fri, Oct 23, 2015 at 9:34 AM, Rousselot, Richard A <
> > > Richard.A.Rousselot at centurylink.com> wrote:
> > >
> > > > Scott,
> > > >
> > > > I agree with everything you said but...  To me if a program/CPU
> > evaluates
> > > > something internally, then when it reports the result it should be
> the
> > > > result as it sees it.  It shouldn't report something different.
> > > >
> > >
> > > This is true to an extent, and there are ways to display something
> "more
> > > exact". But the library programmers wrote code to format floating point
> > > numbers in a way that is appropriate for display to humans. Knowing
> that
> > > floating point calculations are inexact, they round values after a
> > certain
> > > number of decimal places, as most applications expect to see something
> > like
> > > "25" not "24.9999999999999995" (numbers made up).
> > >
> > >
> > > >
> > > > So using your analogy, I ask a English speaking person a two
> > interrelated
> > > > questions, they translate the questions to Japanese in their head,
> then
> > > > answers one question in Japanese and another in English.  I say pick
> a
> > > > language and stick with it.  Either answer my question all in English
> > or
> > > > all in Japanese don't mix it.
> > > >
> > > > I think we are getting to hung up on the details of what is going on
> > > > internally.  The real question is why don't the two results, which
> are
> > > > coming from the same program, agree?  (i.e. return 22.99999999999999
> > not
> > > > 23.0)
> > > >
> > > > Richard
> > > >
> > > > -----Original Message-----
> > > > From: sqlite-users-bounces at mailinglists.sqlite.org [mailto:
> > > > sqlite-users-bounces at mailinglists.sqlite.org] On Behalf Of Scott
> Hess
> > > > Sent: Friday, October 23, 2015 10:05 AM
> > > > To: General Discussion of SQLite Database
> > > > Subject: Re: [sqlite] Simple Math Question
> > > >
> > > > On Fri, Oct 23, 2015 at 7:39 AM, Dominique Devienne <
> > ddevienne at gmail.com
> > > >
> > > > wrote:
> > > >
> > > > > On Fri, Oct 23, 2015 at 4:16 PM, Rousselot, Richard A <
> > > > > Richard.A.Rousselot at centurylink.com> wrote:
> > > > > > So I decided to output 1000 digits, because why not?  So now I am
> > > > > > more perplexed with all these digits showing it is working the
> > > > > > opposite of
> > > > > how I
> > > > > > expected it.  Why is the second set of equations evaluating to a
> > > "yes"
> > > > > when
> > > > > > it is the only one that is obviously NOT equal to the
> expression???
> > > > >
> > > > > Indeed, that's puzzling :)
> > > >
> > > >
> > > > Just to be clear, though, how floating-point numbers work is breaking
> > > your
> > > > expectations because your expectations are wrong when applied to
> > > > floating-point numbers.  Internally, they are base-2 scientific
> > notation,
> > > > so asking for more significant digits in the base-10 representation
> > won't
> > > > help - base-10 fractional numbers cannot always be represented
> > precisely
> > > in
> > > > base-2, ALSO base-2 fractional numbers cannot always be represented
> > > > precisely in base-10, so it's like a game of telephone where you can
> > end
> > > up
> > > > slightly removed from where you started out, even though it seems
> like
> > > it's
> > > > a simple round trip.  Since each individual digit cannot be
> represented
> > > > perfectly, it doesn't matter how many digits of precision you ask
> for,
> > > > you'll always be able to find cases where it doesn't line up like you
> > > > expect.
> > > >
> > > > Think of it this way: Find an English sentence, and find an English
> to
> > > > Japanese translator.  Translate each individual word of the sentence
> > from
> > > > English to Japanese, then concatenate the results together.  Then
> > > translate
> > > > the entire original sentence to Japanese.  The results will almost
> > never
> > > be
> > > > the same.  Then do the same process translating the Japanese back to
> > > > English.  Again, the two routes will provide different results, _and_
> > > both
> > > > of those results will almost certainly not match the original English
> > > > sentence.  This isn't a reflection of the translator's abilities at
> > all.
> > > >
> > > > I'm not saying the computer is always right, just that the computer
> is
> > > > following a very strict recipe with reproducible results.  I don't
> mean
> > > > reproducible like your three examples make logical sense to you, the
> > > user,
> > > > I mean reproducible like my Intel box gives the same results as my
> AMD
> > > box
> > > > as my ARM box.  If you want to be able to deal with fractional
> decimal
> > > > values with high fidelity, you either need to arrange for base-10
> > > > representation (slow, because computers have to simulate it), or you
> > have
> > > > to do your math in shifted fashion (fast, but can be error prone).
> > > >
> > > > -scott
> > > > _______________________________________________
> > > > sqlite-users mailing list
> > > > sqlite-users at mailinglists.sqlite.org
> > > > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> > > > This communication is the property of CenturyLink and may contain
> > > > confidential or privileged information. Unauthorized use of this
> > > > communication is strictly prohibited and may be unlawful. If you have
> > > > received this communication in error, please immediately notify the
> > > sender
> > > > by reply e-mail and destroy all copies of the communication and any
> > > > attachments.
> > > > _______________________________________________
> > > > sqlite-users mailing list
> > > > sqlite-users at mailinglists.sqlite.org
> > > > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> > > >
> > >
> > >
> > >
> > > --
> > > Scott Robison
> > > _______________________________________________
> > > sqlite-users mailing list
> > > sqlite-users at mailinglists.sqlite.org
> > > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> > >
> > _______________________________________________
> > sqlite-users mailing list
> > sqlite-users at mailinglists.sqlite.org
> > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> >
>
>
>
> --
> Scott Robison
> _______________________________________________
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>

Reply via email to