> ~ Online tutorial


Maths Errors
Mathematical functions can be delicate animals. There exist mathematical functions which simply cannot produce sensible answers in all possible cases. Mathematical functions are not "user friendly"! One example of an unfriendly function is the inverse sine function asin(x) which only works for values of x in the range +1.0 to -1.0. The reason for this is a mathematical one: namely that the sine function (of which asin() is the opposite) only has values in this range. The statement
 y = asin (25.3);

is nonsense and it cannot possibly produce a value for y, because none exists. Similarly, there is no simple number which is the square root of a negative value, so an expression such as:
 x = sqrt(-2.0);

would also be nonsense. This doesn't stop the programmer from writing these statements though and it doesn't stop a faulty program from straying out of bounds. What happens then when an erroneous statement is executed? Some sort of error condition would certainly have to result.
In many languages, errors, like the ones above, are terminal: they cause a program to stop without any option to recover the damage. In C, as the reader might have come to expect, this is not the case. It is possible (in principle) to recover from any error, whilst still maintaining firm control of a program.
Errors like the ones above are called domain errors (the set of values which a function can accept is called the domain of the function). There are other errors which can occur too. For example, division by zero is illegal, because dividing by zero is "mathematical nonsense" - it can be done, but the answer can be all the numbers which exist at the same time! Obviously a program cannot work with any idea as vague as this. Finally, in addition to these "pathological" cases, mathematical operations can fail just because the numbers they deal with get too large for the computer to handle, or too small, as the case may be.
Domain error
Illegal value put into function
Division by zero
Dividing by zero is nonsense.
Overflow
Number became too large
Underflow
Number became too small.
Loss of accuracy
No meaningful answer could be calculated

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: