Messages in this thread
 Date Thu, 25 Apr 2002 10:22:49 -0400 (EDT) From "Richard B. Johnson" <> Subject Re: FPU, i386
`On Thu, 25 Apr 2002, rpm wrote:> On Wednesday 17 April 2002 08:10 pm, Jesse Pollard wrote:> > ---------  Received message begins Here  ---------> >> > > if (int(1/h * 100) == int(5.0 * 100))> >> > will give a "proper" result within two decimal places. This is still> > limited since there are irrational numbers within that range that COULD> > still come out with a wrong answer, but is much less likely to occur.> >> > Exact match of floating point is not possible - 1/h is eleveated to a> > float.> >> > If your 1/h was actually num/h, and num computed by summing .01 100 times> > I suspect the result would also be "wrong".> >> > why is exact match of floating point not possible ?Because many (read most) numbers are not exactly representablein floating-point. The purpose of floating-point it to representreal numbers with a large dynamic range. The trade-off is thatfew such internal representations are exact.As a simple example, 0.33333333333.....  can't be represented exactlyeven with paper-and-pencil. However, as the ratio of two integersit can be represented exactly, i.e., 1/3 . Both 1 and 3 mustbe integers to represent this ratio exactly.All real numbers (except trancendentials) can represented exactlyas the ratio of two integers but floating-point uses only onevalue, not two integers, to represent the value. So, an exactrepresentation of a real number, when using a single variablein a general-purpose way, is, for all practical purposes, notpossible. Instead, we get very close.When it comes to '==' close is not equal. There are macros in<math.h> that can be used for most floating-point logic. Youshould check them out. If we wanted to check for '==' we reallyneed to do something like this:    double a, b;    some_loop() {       if(fabs(a-b) < 1.0e-38)           break;     }Where we get the absolute value of the difference between twoFP variables and compare against some very small number.To use the math macros, the comparison should be something like:        if (isless(fabs(a-b), 1.0e-38))             break;Cheers,Dick JohnsonPenguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).                 Windows-2000/Professional isn't.-To unsubscribe from this list: send the line "unsubscribe linux-kernel" inthe body of a message to majordomo@vger.kernel.orgMore majordomo info at  http://vger.kernel.org/majordomo-info.htmlPlease read the FAQ at  http://www.tux.org/lkml/`

Last update: 2005-03-22 13:25    [W:0.085 / U:13.464 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site