Datasheet
Floating-point Support
ARM DUI 0067D Copyright © 1999-2001 ARM Limited. All rights reserved. 5-21
When the operation is a comparison, the result must be returned as if it were an
int
, and must be one of the four values shown in Table 5-11.
Input and output types are the same for all operations except Compare and
Convert.
Example 5-1 shows a custom exception handler. Suppose you are converting some
Fortran code into C. The Fortran numerical standard requires 0 divided by 0 to be 1,
whereas IEEE 754 defines 0 divided by 0 to be an Invalid Operation and so by default
it returns a quiet NaN. The Fortran code is likely to rely on this behavior, and rather than
modifying the code, it is probably easier to make 0 divided by 0 return 1.
A handler function that does this is shown in Example 5-1.
Example 5-1
__softfp __ieee_value_t myhandler(__ieee_value_t op1, __ieee_value_t op2,
__ieee_edata_t edata)
{
__ieee_value_t ret;
if ((edata & FE_EX_FN_MASK) == FE_EX_FN_DIV) {
if ((edata & FE_EX_INTYPE_MASK) == FE_EX_INTYPE_FLOAT) {
if (op1.f == 0.0 && op2.f == 0.0) {
ret.f = 1.0;
return ret;
}
}
if ((edata & FE_EX_INTYPE_MASK) == FE_EX_INTYPE_DOUBLE) {
if (op1.d == 0.0 && op2.d == 0.0) {
ret.d = 1.0;
return ret;
}
}
}
Table 5-11 FE_EX_CMPRET_MASK comparison type flags
Flag Comparison
FE_EX_CMPRET_LESS
op1 is less than op2
FE_EX_CMPRET_EQUAL
op1 is equal to op2
FE_EX_CMPRET_GREATER
op1 is greater than op2
FE_EX_CMPRET_UNORDERED
op1 and op2 are not comparable