The DFPAL Library, version 2.20
© Copyright IBM Corporation, 2007. All rights reserved.
[previous | contents | next] [printer friendly]

Floating point controls: rounding mode, exception and trap handling

These routines allow decimal floating point control, influencing decimal floating point arithmetic. The decimal floating point arithmetic unit (either decNumber or POWER6 processor) indicates exceptions conditions (overflow, underflow, divide by zero, invalid operation, inexact) by setting relevant status bits in the status field. The IEEE 754r (draft) standard requires following five exceptions, invalid operation, overflow, underflow, divide by zero, and inexact. For details about when these exception conditions arise refer to General Decimal Arithmetic Specification.

The following guidelines shall be observed with DFPAL.






Exception status flag management

The following routines allow accessing and altering decimal floating point exception status value. DFPAL provides the following exception status flags. An application must use following defines to access the exception flags. For details about when the exceptions are raised refer to General Decimal Arithmetic Specification.

void dfpalClearStatusFlag(dfpalflag_t mask)

Clear exception status flags specified by the mask parameter. A bit value of 1 in mask will clear that particular exception status flag. The exception status flags can be bitwise or’ed together indicating multiple status flag to be cleared. The exception status flag remains unchanged if the corresponding bit value is 0 in the mask.

void dfpalClearAllStatusFlag()

Clear all exception status flags. This function is equivalent to, but relatively faster than dfpalClearStatusFlag() function with DFPAL_FP_ALL argument.

void dfpalSetStatusFlag(dfpalflag_t mask)

Set exception status flags specified by the mask parameter. Bit value of 1 in the mask will set that flag, value of 0 will clear the flag.

dfpalflag_t dfpalReadStatusFlag(void)

Read current exception status flags. Return value of the function can be used in bitwise and operation to check presence of particular exception status.

dfpalflag_t dfpalSwapStatusFlag(dfpalflag_t mask)

This is combination of the dfpalSetStatusFlag() and the dfpalReadStatusFlag(). Read and return current exception status flags, set exception status flags specified by the mask parameter.

Exception trap management

The following routines allow accessing and altering decimal floating point trap control. DFPAL provides the following trap control flags. An application must use following defines to access the trap control flags. SIGFPE is raised when trap is enabled for that particular exception.

void dfpalEnableTrap(dfpaltrap_t mask)

Enable floating point trap for exception(s) specified by the mask parameter. Bit value of 1 will turn on trap for that particular exception. The traps can be bitwise or’ed together to indicate multiple traps to be enabled.

void dfpalEnableAllTrap(void)

Enable all five floating point exception traps.

void dfpalDisableTrap(dfpaltrap_t mask)

Disable floating point trap for exception(s) specified by the mask parameter. Bit value of 1 will turn off trap for that particular exception. The traps can be bitwise or’ed together to indicate multiple traps to be disabled.

void dfpalDisableAllTrap(void)

Disable all five floating point exception traps.

uint8_t dfpalAnyTrapEnabled(void)

Returns boolean value 1 if any trap is enabled, 0 otherwise.

uint8_t dfpalTrapEnabled(dfpaltrap_t mask)

Returns boolean value 1 if any of the trap(s) specified by the mask parameter is enabled, 0 otherwise.




Rounding mode control

The following routines allow controlling and accessing decimal floating point rounding mode. DFPAL provides the following rounding mode definitions. An application must use following defines to access the exception flags. For details about how rounding mode influence decimal floating point arithmetic refer to General Decimal Arithmetic.

dfpalrnd_t dfpalReadRoundingMode(void)

Return current rounding mode.

dfpalrnd_t dfpalSwapRoundingMode(dfpalrnd_t rndmode)

Return current rounding mode and set rounding mode specified by the rndmode parameter.

void dfpalSetRoundingMode(dfpalrnd_t rndmode)

Set rounding mode specified by the rndmode parameter.

uint8_t dfpalSetExponentClamp(uint8_t) [deprecated]

Set exponent clamp for decNumber context. Do not use this function.
[previous | contents | next]

DFPAL is authored by Punit Shah (punit@us.ibm.com).
Please send any corrections, comments or questions to dfpal-l@austin.ibm.com.
This page was updated on 21 Dec 2007.