Re: Solution for Floating-Point Errors
- From: Lee <REM0VElbspamtrap@xxxxxxx>
- Date: 23 Jul 2007 17:22:04 -0700
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.
--
.
- Follow-Ups:
- Re: Solution for Floating-Point Errors
- From: David Mark
- Re: Solution for Floating-Point Errors
- References:
- Solution for Floating-Point Errors
- From: vunet . us
- Re: Solution for Floating-Point Errors
- From: David Mark
- Solution for Floating-Point Errors
- Prev by Date: Re: Interesting Situation - Need Modeless Window Help
- Next by Date: Re: Solution for Floating-Point Errors
- Previous by thread: Re: Solution for Floating-Point Errors
- Next by thread: Re: Solution for Floating-Point Errors
- Index(es):
Relevant Pages
|
Loading