Off Topic — HabitableZone

Off Topic » in reply to Division by zero = infinity?

re: Round-off errors more deadly at run-time

Suppose you have a function like:

theta = arccos(X)

In real-life the function will only accept values between -1 and 1 otherwise it generates an error, even on a pocket calculator.

Since Visual Basic doesn't support the inverse cosine function, you have to use the equivalent derived trig function based on the inverse tangent function:

Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)

Therefore the new formula is as follows,

theta = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)

If X = 1 or X = -1 there is now a problem because several operations have to be performed on X before the Atn is invoked. It is possible that a round-off error, perhaps in the 15th-decimal place will create a number that is outside the range of acceptable values for the Inverse Tangent function. It will not accept the number and generate an error.

I can't explain how frustrating this error is. I doubt that even a university could invent a more torturous exam, or series of exams, each lasting several hours, where you pass by the skin of your teeth via the "last question first, first question last" strategy, and a set of formula sheets shrunken down by 50% on a photocopier, so that they will fit on the 2-double-page cheat sheet allowance...... (may consider counselling for this)

Log in or register to post.

The whole thread (4 posts)