Re: Weird result returned from adding floats depending on order I add them



On Feb 21, 2:05 am, Grant Edwards <gra...@xxxxxxxx> wrote:
On 2007-02-20, joanne matthews (RRes-Roth) <joanne.matth...@xxxxxxxxxxx> wrote:

I'm getting different results when I add up a list of floats depending
on the order that I list the floats.


Don't use floating point if you expect exact results.

It's not the floating point that's the problem, it's the radix, in
this case 2, not being able to express n/10 exactly. As the tutorial
points out, radix-10 has problems representing n/3 (and n/7 and ...)
exactly.

Another take: Don't expect exact results. If the input is exact to 1
or two decimal places, don't expect the sum to be exact to 15 or more
decimal places.

.



Relevant Pages

  • Re: Feature suggestion: sum() ought to use a compensated summation algorithm
    ...  Your algorithm is specific to floats. ... sum() seems to be most useful for numeric types (i.e. those ... may be either exact or inexact (e.g. floating point ... compensated summation for built-in floating point types. ...
    (comp.lang.python)
  • Re: Feature suggestion: sum() ought to use a compensated summation algorithm
    ... Your algorithm is specific to floats. ... Or is this just a special exception to prevent the misuse of sum to join strings? ... For exact types it does not make sense to use compensated summation, and sumcannot decide whether a user-defined type is exact or inexact. ...
    (comp.lang.python)
  • Re: Float comparison
    ... Oh, it exists, but not in that floating representation. ... Keith has already mentioned the need to do an error analysis if you want to know what the possible error. ... I know of code which carefully uses doubles to do integer arithmetic, staying within the range where integers can be represented exactly, in order to use the greater range of exact integral values that a double can represent on that specific implementation than an int. ... So either integer types cannot store exact values and you need to do a full error analysis to determine the range of values they might represent or floating point variables can store exact values which are exactly the mathematically correct values the program is intended to store. ...
    (comp.lang.c)
  • Re: Cant get Access to run a query with a time field
    ... Since the user enters an exact value, why isn't it saved to the ... Second, a date time value is a floating point value, ... >> Vanderghast, Access MVP ...
    (microsoft.public.access.queries)
  • Re: Wrong results when comparing negative double variables in an if statement
    ... debugging purposes, not because floating-point numbers have hundreds ... >The output as copied from the emulated DOS window is: ... There is no exact value of 0.001 in binary floating point, ...
    (comp.lang.c)