TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
ASML C Coding Standard
Search

Rule:  7.12.aChecked automatically with code checker

Synopsis:The arguments to any mathematical function shall be within the appropriate range.
Language:C
Severity Level:2
Category:Library


Description:

Justification

When supplied a bad argument, the returned value cannot be used, as it is either NAN or an implementation specific value.

Example 1

alpha = asin(a / c); /* WRONG if abs(argument) can be > 1 */
r = a / c; /* RIGHT: check argument before use */
if (abs(r) > 1)
{
   /* handle error */
}
else
{
   alpha = asin(r);
}

Example 2

c = sqrt(b * b - a * a); /* WRONG if argument can be negative */
d = (b * b) - (a * a); /* RIGHT: check computation result */
if (d < 0)
{
   /* handle error */
}
else
{
   c = sqrt(d);
}

Note

Math functions with "out of range" risk are "asin", "acos", "sqrt", "log", and "log10".