![]() ![]() The C Standard, 7.12.1, defines the following behavior for floating-point overflow:Ī floating result overflows if the magnitude of the mathematical result is finite but so large that the mathematical result cannot be represented without extraordinary roundoff error in an object of the specified type. The exact treatment of error conditions from math functions is tedious. Programmers usually cannot prevent range errors, so the most reliable way to handle them is to detect when they have occurred and act accordingly. The most reliable way to handle domain and pole errors is to prevent them by checking arguments beforehand, as in the following exemplar:įprintf(stderr, "sqrt requires a nonnegative argument") The standard math functions not listed in this table, such as fabs(), have no domain restrictions and cannot result in range or pole errors.įmod(x, y), remainder(x, y), remquo(x, y, quo) The programmer must also check for range errors where they might occur. If a function has a specific domain over which it is defined, the programmer must check its input values. Both float and long double forms of these functions also exist but are omitted from the table for brevity. ![]() The following table lists the double forms of standard mathematical functions, along with checks that should be performed to ensure a proper input domain, and indicates whether they can also result in range or pole errors, as reported by the C Standard. Instead of preventing range errors, programmers should attempt to detect them and take alternative action if a range error occurs. Range errors usually cannot be prevented because they are dependent on the implementation of floating-point numbers as well as on the function being applied. Programmers can prevent domain and pole errors by carefully bounds-checking the arguments before calling mathematical functions and taking alternative action if the bounds are violated. An example of a pole error is log(0.0), which results in negative infinity. In both cases, the function will return some value, but the value returned is not the correct result of the computation. Contrastingly, 10 raised to the 1-millionth power, pow(10., 1e6), cannot be represented in many floating-point implementations because of the limited range of the type double and consequently constitutes a range error. Paragraph 2 statesĪ domain error occurs if an input argument is outside the domain over which the mathematical function is defined.Ī pole error (also known as a singularity or infinitary) occurs if the mathematical function has an exact infinite result as the finite input argument(s) are approached in the limit.Ī range error occurs if the mathematical result of the function cannot be represented in an object of the specified type, due to extreme magnitude.Īn example of a domain error is the square root of a negative number, such as sqrt(-1.0), which has no meaning in real arithmetic. The C Standard, 7.12.1, defines three types of errors that relate specifically to math functions in. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |