Re: Solution for Floating-Point Errors



David Mark said:

On Jul 23, 6:31 pm, Lee <REM0VElbspamt...@xxxxxxx> wrote:
David Mark said:







On Jul 23, 6:08 pm, Randy Webb <HikksNotAtH...@xxxxxxx> wrote:
David Mark said the following on 7/23/2007 5:28 PM:

On Jul 23, 4:35 pm, vunet...@xxxxxxxxx wrote:
Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.00831109999999999999
can I avoid this by a better method than comparing 2 number length
after decimal point and using toFixed() to match shorter number with
another one?
Thanks.

Yes. To make it simpler, multiply each by 1000000 before adding:

8310 + 1 = 8311

0.00831 + 0.000001 != 8311

To compare the result, as per my post, you have to multiply both sides
of the equation. I don't know how much more explicit I could have
made this and the OP obviously understood.

Saying "multiply each ... before adding" suggests that the things
referred to by "each" are also the things that you are adding, so

Of course they are.

you certainly could have been much more clear about specifying
that you also have to multiply the comparison target.

How much more clear could the example be? It explicitly shows the new
equation.


How is it obvious that the OP understood? For all we know, he's

Because he said so. And now two other posters have muddled the issue
and confused him. How do I know that? Read the thread.

You believe that, because a person says he understands your
solution, that he must actually "obviously" understand it?
Clearly you've never been involved in any sort of user support.

Your explanation is incomplete in that it doesn't clearly
specify that, in addition to multiplying each of the addends
before the addition, that you also multiply the value you're
using for comparison. As I said before, "multiply each ...
before adding" leads one to believe that you are talking only
about the numbers that you are adding.

currently scratching his head because your solution, which seems

No. Read the thread.

so simple, doesn't work when implemented.

The example equation "works" fine, in that both sides are equal.

Only if you interpret it as you intended, as opposed to how
you described it.


--

.



Relevant Pages

  • Re: Solution for Floating-Point Errors
    ... can I avoid this by a better method than comparing 2 number length ... after decimal point and using toFixedto match shorter number with ... Clearly you are more interested in me than in helping the OP, ... in addition to multiplying each of the addends ...
    (comp.lang.javascript)
  • Re: Some FEM questions
    ... >> you get a stiff equation and integrating this one by an explicit ... ode explicit by multiplying with inverse, ...
    (sci.math.num-analysis)
  • Re: Solution for Floating-Point Errors
    ... can I avoid this by a better method than comparing 2 number length ... after decimal point and using toFixedto match shorter number with ... I don't know how much more explicit I could have ...
    (comp.lang.javascript)
  • Re: How to solve (2x + 3y)^3?
    ... dwwdkddb wrote: by multiplying by and then multiplying the result by. ... avoid using brute force whenever it can be done faster by some more general method. ...
    (sci.math)
  • Re: Solution for Floating-Point Errors
    ... can I avoid this by a better method than comparing 2 number length ... after decimal point and using toFixedto match shorter number with ... I don't know how much more explicit I could have ...
    (comp.lang.javascript)

Loading