Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.0083110999999 9999999
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. 24 3257
On Jul 23, 4:35 pm, vunet...@gmail. com wrote:
Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.0083110999999 9999999
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
On Jul 23, 5:28 pm, David Mark <dmark.cins...@ gmail.comwrote:
On Jul 23, 4:35 pm, vunet...@gmail. com wrote:
Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.0083110999999 9999999
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
very good. thank you.
David Mark said the following on 7/23/2007 5:28 PM:
On Jul 23, 4:35 pm, vunet...@gmail. com wrote:
>Is there a good solution for floating-point errors? If I got: 0.00831 + 0.000001 = 0.0083110999999 9999999 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
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
On Jul 23, 6:08 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
David Mark said the following on 7/23/2007 5:28 PM:
On Jul 23, 4:35 pm, vunet...@gmail. com wrote:
Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.0083110999999 9999999
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.
David Mark said:
> On Jul 23, 6:08 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
>David Mark said the following on 7/23/2007 5:28 PM:
On Jul 23, 4:35 pm, vunet...@gmail. com wrote: Is there a good solution for floating-point errors? If I got: 0.00831 + 0.000001 = 0.0083110999999 9999999 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
you certainly could have been much more clear about specifying
that you also have to multiply the comparison target.
How is it obvious that the OP understood? For all we know, he's
currently scratching his head because your solution, which seems
so simple, doesn't work when implemented.
--
How is it obvious that the OP understood?
Let's see: 0.00831 + 0.000001 = 0.008311
(0.00831*100000 0) + (0.000001*10000 00) == 0.008311/1000000
8310 + 1 = 8311/1000000
thus ==0.008311
What does everyone think? I'd appreciate a better way of handling this
if there is one...
Thanks
On Jul 23, 6:31 pm, Lee <REM0VElbspamt. ..@cox.netwrote :
David Mark said:
On Jul 23, 6:08 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
David Mark said the following on 7/23/2007 5:28 PM:
On Jul 23, 4:35 pm, vunet...@gmail. com wrote:
Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.0083110999999 9999999
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.
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.
David Mark said the following on 7/23/2007 7:24 PM:
On Jul 23, 6:31 pm, Lee <REM0VElbspamt. ..@cox.netwrote :
>David Mark said:
>>On Jul 23, 6:08 pm, Randy Webb <HikksNotAtH... @aol.comwrote: David Mark said the following on 7/23/2007 5:28 PM: On Jul 23, 4:35 pm, vunet...@gmail. com wrote: >Is there a good solution for floating-point errors? >If I got: >0.00831 + 0.000001 = 0.0083110999999 9999999 >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.
Answer:
Multiply both of your decimals by 100000 (in this case), add them, then
divide the answer by 100000 to get the decimal back.
You wanted more clear, you got it.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
On Jul 23, 7:35 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
David Mark said the following on 7/23/2007 7:24 PM:
On Jul 23, 6:31 pm, Lee <REM0VElbspamt. ..@cox.netwrote :
David Mark said:
>On Jul 23, 6:08 pm, Randy Webb <HikksNotAtH... @aol.comwrote: David Mark said the following on 7/23/2007 5:28 PM: On Jul 23, 4:35 pm, vunet...@gmail. com wrote: Is there a good solution for floating-point errors? If I got: 0.00831 + 0.000001 = 0.0083110999999 9999999 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.
Answer:
Multiply both of your decimals by 100000 (in this case), add them, then
divide the answer by 100000 to get the decimal back.
You've done it again. There are six decimal places to shift (in this
case), not five. 100000 != 1000000.
And what the hell does "get the decimal back" mean anyway? Same for
"multiply both of your decimals."
You wanted more clear, you got it.
I didn't want anything. The OP wanted an answer and got it and
followed up to say it worked. Now you have made a real mess of
things. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: George Hester |
last post by:
At the time this suggestion was made I didn't have the wherewithall to even attempt it. But over time I learned enough to make a stab at it. Let just say the foating DIV had to provide the same advantages as a chromeless window else it really wouldn''t help.
You see the idea is that the chromeless window forces a client to make a choice. It...
|
by: DraguVaso |
last post by:
Hi,
When you double click on a form in the Solution Explorer, it will show that
form in the Designe Mode. Is there a way to change this, so it will switcvh
to the 'Code Mode'?
Is this possible or not?
thanks a lot!
|
by: meltedown |
last post by:
I would like the floating divs to float and then the header to come
after them , on the left. That's what I thought clearing the floats was
for, but in this example, the header is to the right of the floating
divs, nothing is cleared. What am I doing wrong ?
Here is the url:http://www.reenie.org/test/test5.php
Here is the code:
<html>...
|
by: buliwyf_23 |
last post by:
I have this:
CSize sz;
sz.cx = dwOutX1;
sz.cy = dwOutY1;
CPoint pt(sz);
ClientToScreen(&pt);
|
by: Usenet |
last post by:
I might be being silly here.
On my links page I've got a whole load of floating boxes, which I'm
really pleased with.
But then I want the footer to be *below* them.
On my current site (http://www.vowleyfarm.co.uk/CommunityLinks.htm)
I've cheated by putting the footer in a floating box as well, but now
I'm moving to using a CMS I would...
| |
by: Qiang |
last post by:
Those who have used Google notebook may notice that google notebook
displays the notes in a small floating window of the browser. I have
tried to create a similar floating window, but with no luck. Dojo has a
sample floating window, but that floating window has to exist in a
browser page, but looks like Google's floating window can exist...
|
by: mscertified |
last post by:
My solution explorer window used to be over to the right of my screen. I have
no idea how it happened but now it is a free floating window with no minimize
button. I have to drag it out of sight to be able to use the screen then drag
it back when I need it. I've looked in Help for hours but cannot find how to
put this window back where it...
|
by: gdrenfrew |
last post by:
I'd like to know if it is possible to stop the parent application of a floating form becoming active when the controls on the floating form are clicked?
I've got a large application, with multiple embedded controls. Some of the controls can be detached on effectively floating forms, which can be dragged about the screen. Not using MDI type...
|
by: murali.desikan |
last post by:
Hi,
The definition of floating literal in the C++ (ISO/IEC 14882:2003)
grammar is as follows (Note: I have replaced the "opt" subscript used
in the standard with to indicate optional symbol).
------BEGIN------
floating-literal:
fractional-constant
digit-sequence exponent-part
|
by: Jeremy |
last post by:
I've got a floating div which becomes visible when a link is clicked. I
want the div to be hidden when the user clicks anywhere on the page except
for whithin the div. What is the best way to do this? Really, I only need
to support ie6+ but cross browser is always nice.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |