Re: Solving Triangles



> Dim Dx As Double, Dy As Double
> .....<snip>.....
> Dx = X2 - X1
> .....<snip>.....
> If Dx = 0 Then
> .....<snip>.....

It is not advisable to test the contents of a Double variable for equality
to zero. Here is an example why...

X1 = 12.543
X2 = 12.4 + 0.143
Dx = X2 - X1
If Dx = 0 Then
MsgBox "Equal"
Else
MsgBox "Not Equal"
End If

Even though, mathematically, 12.4 plus 0.143 does equal 12.543, the
realities of implementing floating point numbers on a PC means this will not
always be the case. Here are some links that explain the problem...

INFO: Visual Basic and Arithmetic Precision
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q279/7/55.ASP&NoWebContent=1

(Complete) Tutorial to Understand IEEE Floating-Point Errors
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q42/9/80.ASP&NoWebContent=1

What Every Computer Scientist Should Know About Floating Point
http://docs.sun.com/source/806-3568/ncg_goldberg.html

So, what are you supposed to do? Simple. Decide on a value which is near
enough to zero to be considered zero and see if the absolute value is
smaller than it. If so, consider it to be zero. An example, using your
If-Then statement above...

If Abs(Dx) < 1e-13 Then

Rick


.



Relevant Pages

  • REPRESENT revisited
    ... Forth-94 has few floating point display functions [none in the ... If u is greater than zero the character string shall consist ... If u is zero the string shall consist of one digit representing ...
    (comp.lang.forth)
  • Re: Floating point errors in collision routines
    ... > Trying to converge a floating point calculation all the way to ... > zero is fundamentally futile. ... > Newer collision engines, like Gino's SOLID, get ... >> the plane.) ...
    (comp.lang.cpp)
  • Cfv: Floating point truncation
    ... RfD: Floating point truncation ... which, respectively, provide rounding to the nearest integer, and rounding to the nearest integer on the side of the number line towards negative infinity. ... ANS Forth does not provide a word for rounding towards zero, and returning a floating point representation of the resulting integer. ... Include a standard word, named "FTRUNC", to perform "truncation", i.e. rounding of a floating point number towards zero, returning a floating point representation of the resulting integer. ...
    (comp.lang.forth)
  • Re: Floating point arithmetic (epsilon)
    ... little point in using byte compiled code for numerics when you have access ... >we don't know the real root ahead of time. ... >enough to zero" means. ... Think not of zero when you use floating point code. ...
    (comp.lang.lisp)
  • Re: Pi.
    ... Furthermore, with binary floating point, the spacings between the candidate return values for the floating point SINare much closer than the spacings of the nearby input values, so the return value of zero should never be chosen. ... applications of harmonic analysis so that the "two pi" is closer to a symbolic parameter. ... Fourier analysis is often expressed in terms of a character function with period of one, rather than the sines and cosines of calculus. ...
    (comp.lang.fortran)