Keil Logo

Technical Support

On-Line Manuals

Libraries and Floating Point Support Guide

Preface The ARM C and C++ Libraries The ARM C Micro-library Floating-point Support About floating-point support The software floating-point library, fplib Calling fplib routines fplib arithmetic on numbers in a particular format fplib conversions between floats, long longs, doub fplib comparisons between floats and doubles fplib C99 functions Controlling the ARM floating-point environment Floating-point functions for compatibility with Mi C99-compatible functions for controlling the ARM f C99 rounding mode and floating-point exception mac Exception flag handling Functions for handling rounding modes Functions for saving and restoring the whole float Functions for temporarily disabling exceptions ARM floating-point compiler extensions to the C99 Writing a custom exception trap handler Example of a custom exception handler Exception trap handling by signals mathlib double and single-precision floating-point IEEE 754 arithmetic Basic data types for IEEE 754 arithmetic Single precision data type for IEEE 754 arithmetic Double precision data type for IEEE 754 arithmetic Sample single precision floating-point values for Sample double precision floating-point values for IEEE 754 arithmetic and rounding Exceptions arising from IEEE 754 floating-point ar Exception types recognized by the ARM floating-poi Using the Vector Floating-Point (VFP) support libr The C and C++ Library Functions reference Floating-point Support Functions Reference

Exception types recognized by the ARM floating-point environment

3.5.8 Exception types recognized by the ARM floating-point environment

The ARM® floating-point environment recognizes a number of different types of exception.

The following types of exception are recognized:
Invalid Operation exception
This occurs when there is no sensible result for an operation. This can happen for any of the following reasons:
  • Performing any operation on a signaling NaN, except the simplest operations (copying and changing the sign).
  • Adding plus infinity to minus infinity, or subtracting an infinity from itself.
  • Multiplying infinity by zero.
  • Dividing 0 by 0, or dividing infinity by infinity.
  • Taking the remainder from dividing anything by 0, or infinity by anything.
  • Taking the square root of a negative number (not including minus zero).
  • Converting a floating-point number to an integer if the result does not fit.
  • Comparing two numbers if one of them is a NaN.
If the Invalid Operation exception is not trapped, these operations return a quiet NaN. The exception is conversion to an integer. This returns zero because there are no quiet NaNs in integers.
Divide by Zero exception
This occurs if you divide a finite nonzero number by zero. Be aware that:
  • Dividing zero by zero gives an Invalid Operation exception.
  • Dividing infinity by zero is valid and returns infinity.
If Divide by Zero is not trapped, the operation returns infinity.
Overflow exception
This occurs when the result of an operation is too big to fit into the format. This happens, for example, if you add the largest representable number to itself. The largest float value is 0x7F7FFFFF.
If Overflow is not trapped, the operation returns infinity, or the largest finite number, depending on the rounding mode.
Underflow exception
This can occur when the result of an operation is too small to be represented as a normalized number (with Exp at least 1).
The situations that cause Underflow depend on whether it is trapped or not:
  • If Underflow is trapped, it occurs whenever a result is too small to be represented as a normalized number.
  • If Underflow is not trapped, it only occurs if the result requires rounding. So, for example, dividing the float number 0x00800000 by 2 does not signal Underflow, because the result 0x00400000 is exact. However, trying to multiply the float number 0x00000001 by 1.5 does signal Underflow.


    For readers familiar with the IEEE 754 specification, the chosen implementation options in the ARM compiler are to detect tininess before rounding, and to detect loss of accuracy as an inexact result.
    If Underflow is not trapped, the result is rounded to one of the two nearest representable denormal numbers, according to the current rounding mode. The loss of precision is ignored and the system returns the best result it can.
  • The Inexact Result exception happens whenever the result of an operation requires rounding. This would cause significant loss of speed if it had to be detected on every operation in software, so the ordinary floating-point libraries do not support the Inexact Result exception. The enhanced floating-point libraries, and hardware floating-point systems, all support Inexact Result.
    If Inexact Result is not trapped, the system rounds the result in the usual way.
    The flag for Inexact Result is also set by Overflow and Underflow if either one of those is not trapped.
All exceptions are untrapped by default.
Non-ConfidentialPDF file icon PDF versionARM DUI0378H
Copyright © 2007, 2008, 2011, 2012, 2014-2016 ARM. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.