mathlib error handling

In ARM Compiler 4.1 and later, the error handling of mathematical functions is consistent with Annex F of the ISO/IEC C99 standard. In RVCT 4.0 and earlier, it is not.

Show/hidemathlib error handling in RVCT 4.0 and earlier

To invoke RVCT 4.0 and earlier behavior, you can define __use_rvct_matherr. Table 10 shows how the math functions respond when supplied with out-of-range arguments.

Table 10. Mathematical functions in RVCT 4.0 and earlier

FunctionConditionReturned valueError number
acos(x)abs(x) > 1QNaNEDOM
asin(x)abs(x) > 1QNaNEDOM
atan2(x,y)x =0, y = 0QNaNEDOM
atan2(x,y)x = Inf, y = InfQNaNEDOM
cos(x)x=InfQNaNEDOM
cosh(x)Overflow+InfERANGE
exp(x)Overflow+InfERANGE
exp(x)Underflow+0ERANGE
fmod(x,y)x=InfQNaNEDOM
fmod(x,y)y = 0QNaNEDOM
log(x)x < 0QNaNEDOM
log(x)x = 0-InfEDOM
log10(x)x < 0QNaNEDOM
log10(x)x = 0-InfEDOM
pow(x,y)Overflow+InfERANGE
pow(x,y)Underflow0ERANGE
pow(x,y)x=0 or x=Inf, y=0+1EDOM
pow(x,y)x=+0, y<0-InfEDOM
pow(x,y)x=-0, y<0 and y integer-InfEDOM
pow(x,y)x= -0, y<0 and y non-integerQNaNEDOM
pow(x,y)x<0, y non-integerQNaNEDOM
pow(x,y)x=1, y=InfQNaNEDOM
sqrt(x)x < 0QNaNEDOM
sin(x)x=InfQNaNEDOM
sinh(x)Overflow+InfERANGE
tan(x)x=InfQNaNEDOM
atan(x)SNaNSNaNNone
ceil(x)SNaNSNaNNone
floor(x)SNaNSNaNNone
frexp(x)SNaNSNaNNone
ldexp(x)SNaNSNaNNone
modf(x)SNaNSNaNNone
tanh(x)SNaNSNaNNone

HUGE_VAL is an alias for Inf. Consult the errno variable for the error number. Other than the cases shown in Table 10, all functions return QNaN when passed QNaN and throw an invalid operation exception when passed SNaN.

The string passed to C99 nan() is ignored, and the same Not a Number (NaN) is always returned, namely the one with all fraction bits clear except the topmost one. The sign bit is also clear. Passing strings of the form NAN(xxxx) to strtod has the same effect.

Show/hideSee also

Copyright © 2010-2011 ARM. All rights reserved.ARM DUI 0475C
Non-ConfidentialID080411