Source code for DFPAL is available from International Components for Unicode (ICU) DFPAL package.
Contents:
It will not be possible for many software vendors to migrate their build environment to the new compiler version required to utilize hardware decimal floating point. Typically, the compiler migration is not a trivial task due to regression, incompatibility and other concerns, furthermore it requires significant amount of resources and efforts. Additionally, such application will not be compatible and portable across platforms or compilers who do not support the decimal floating point feature. An application compiled with POWER6 as a target platform will not function on pre-POWER6 architectures (e.g. POWER5 family of processors) due to newer decimal floating point instructions available only with the POWER6 processor.
Decimal Floating Point Abstraction Layer (DFPAL) addresses these issues. DFPAL allows applications to run virtually on any platform and still provides hardware acceleration on the POWER6 processor. DFPAL provides the following features:
1 #include <stdio.h> // printf() etc. 2 #include <stdlib.h> // malloc()/free() 3 4 #include "dfpal.h" // DFPAL API 5 6 int main(int argc, char **argv) 7 { 8 decimal64 n1, n2, n3; // 64-bit work numbers 9 decimal128 N1, N2, N3; // 128-bit work numbers 10 char dfpstr[64]; // buffer for 'to string' conversion 11 int initErr, initOSErr; // DFPAL initialization error place-holder 12 char *errStr=NULL; // ... 13 14 if (argc < 3) { 15 printf("Please supply two numbers to add.\n"); 16 return(1); 17 } 18 19 // initialize and check error; free memory if unsuccessful 20 if (dfpalInit((void *)malloc(dfpalMemSize())) != DFPAL_ERR_NO_ERROR) { 21 dfpalGetError(&initErr, &initOSErr, &errStr); 22 fprintf(stderr, "DFPAL Init error number:%d, error: %s\n", 23 initErr, errStr); 24 dfpalEnd(free); 25 return(1); 26 } 27 28 // what version? 29 printf("Version of DFPAL: %s\n", dfpalVersion()); 30 31 // Is it running in software or hardware? 32 if (dfpalGetExeMode()!=PPCHW) 33 printf("DFPAL is operating in software\n"); 34 else 35 printf("DFPAL is operating in hardware\n"); 36 37 // convert input strings to decimal64 format 38 n1=dec64FromString(argv[1]); 39 n2=dec64FromString(argv[2]); 40 41 // add 42 n3 = dec64Add(n1,n2); 43 printf("n1 + n2 = %s\n", dec64ToString(n3, dfpstr)); 44 45 // convert decimal64 to decimal128 46 N1=dec128FromDecimal64(n1); // N1=(decimal128)n1 47 N2=dec128FromDecimal64(n2); // N2=(decimal128)n2 48 N3 = dec128Add(N1,N2); 49 printf("N1 + N2 = %s\n", dec128ToString(N3, dfpstr)); 50 51 dfpalEnd(free); // cleanup; free memory used by DFPAL 52 53 return(0); 54 }
dfpal.h
.
decimal64
and decimal128
names to avoid name collision with compiler native decimal floating point data type names.
dfpalInit()
. This example uses memory allocated using malloc()
facility. Application can use its own memory allocation routine.
dfpalEnd()
to cleanup and free memory.
decimal64
format.
decimal64
data type, print result using dec64ToString()
.
decimal64
values to decimal128
type (type conversion).
decimal128
data types, print result using dec128ToString()
.
dfpalEnd()
to cleanup and free memory.
1 #include <stdio.h> // printf() etc. 2 #include <stdlib.h> // malloc()/free() 3 4 #include "dfpal.h" // DFPAL API 5 6 #define PRINT_EXCEPTIONS(where, st) { \ 7 printf(#where "\n"); \ 8 printf("INVALID OVERFLOW UNDERFLOW DIV_BY_ZERO INEXACT\n"); \ 9 printf(" %1d %1d %1d %1d %1d\n", \ 10 ((st)&DFPAL_FP_INVALID)?1:0, ((st)&DFPAL_FP_OVERFLOW)?1:0, \ 11 ((st)&DFPAL_FP_UNDERFLOW)?1:0, ((st)&DFPAL_FP_DIV_BY_ZERO)?1:0, \ 12 ((st)&DFPAL_FP_INEXACT)?1:0); \ 13 } 14 15 16 int main(int argc, char **argv) 17 { 18 decimal64 n1, n2, n3, n4; // 64-bit work numbers 19 decimal128 N1, N2, N3, N4; // 128-bit work numbers 20 char dfpstr[64]; // buffer for 'to string' conversion 21 int initErr, initOSErr; // DFPAL initialization error place-holder 22 char *errStr=NULL; // ... 23 dfpalflag_t xstatus; 24 25 // initialize and check error; free memory if unsuccessful 26 if (dfpalInit((void *)malloc(dfpalMemSize())) != DFPAL_ERR_NO_ERROR) { 27 dfpalGetError(&initErr, &initOSErr, &errStr); 28 fprintf(stderr, "DFPAL Init error number:%d, error: %s\n", 29 initErr, errStr); 30 dfpalEnd(free); 31 return(1); 32 } 33 34 dfpalClearStatusFlag(DFPAL_FP_ALL); 35 36 // create some number to play with 37 n1=dec64FromString("9E+200"); 38 n2=dec64FromString("9E-200"); 39 N1=dec128FromString("9E+3200"); 40 N2=dec128FromString("9E-3200"); 41 // did anything go wrong in string conversion? 42 if ((xstatus=dfpalReadStatusFlag()) & DFPAL_FP_ALL) 43 PRINT_EXCEPTIONS(String Conversion, xstatus); 44 45 // multiplication: this should cause overflow and inexact 46 n3=dec64Multiply(n1,n1); 47 printf("n1 * n2 = %s\n", dec64ToString(n3, dfpstr)); 48 // overflow and inexact should be present 49 if ((xstatus=dfpalReadStatusFlag()) & DFPAL_FP_ALL) 50 PRINT_EXCEPTIONS(decimal64 multiply, xstatus); 51 52 // division: this should cause divide by zero 53 N3=dec128Divide(N1, dec128Zero()); 54 printf("N1 / 0 = %s\n", dec128ToString(N3, dfpstr)); 55 // overflow, inexact, divide by zero should be present 56 if ((xstatus=dfpalReadStatusFlag()) & DFPAL_FP_ALL) 57 PRINT_EXCEPTIONS(decimal64 multiply, xstatus); 58 59 // division: this should cause underflow and inexact 60 N3=dec128Divide(N2,N1); 61 printf("N1 / N2 = %s\n", dec128ToString(N3, dfpstr)); 62 // overflow, inexact, underflow, divide by zero should be present 63 if ((xstatus=dfpalReadStatusFlag()) & DFPAL_FP_ALL) 64 PRINT_EXCEPTIONS(decimal128 divide, xstatus); 65 66 // divide Inf/Inf: should cause invalid 67 n3=dec64Divide(n3, n3); 68 printf("Inf / Inf = %s\n", dec64ToString(n3, dfpstr)); 69 // overflow, inexact, underflow, divide by zero, invalid should be present 70 if ((xstatus=dfpalReadStatusFlag()) & DFPAL_FP_ALL) 71 PRINT_EXCEPTIONS(decimal64 divide, xstatus); 72 73 dfpalEnd(free); // cleanup; free memory used by DFPAL 74 75 return(0); 76 }
dfpal.c |
Main source file; the only C source file. |
asmdfp.S |
POWER6 decimal floating point insturction assembly language code snippets for Linux on Power, for use with GCC compiler on Linux on Power. |
dfpal.h |
DFPAL API specification header file. Applications are required to include this header file into their C source file(s). |
dfpalct.h |
DFPAL context data structure. DFPAL context is persistent data to hold DFPAL runtime state (e.g. exception status, traps, rounding mode etc.). The context data is divided into two parts. A process-wide context (common to all threads) and thread-specific context. This header is not seen by the application. |
dfpaltypes.h |
DFPAL specific data type definitions. This header is used to achieve portability. |
ppcdfp.h |
POWER PC machine instructions for DFP arithmetic. Contains XLC #pragma mc_func macros for in-place instruction expansion. This header is not seen by the application. |
asmdfp.h |
Function prototype decleration corresponding to asmdfp.S snippets. This header is not seen by the application. |
dfpstub.h |
Stub code for POWER PC machine instructions. The stub is used when DFPAL is compiled with no hardware decimal floating point support (using DFPAL_NO_HW_DFP ). This header is not seen by the application. |
dfpalerr.h |
DFPAL error codes and error messages. The error codes and error messages are separated to assist national language support (NLS) message catalog. |
decNumber tuningBeginning decNumber version 3.40, theDECENDIAN setting (in decNumberLocal.h) has been removed to improve performance; instead, you must set the DECLITEND parameter to 1 if compiling for a little-endian target (for example, AMD and Intel x86), or to 0 if compiling for a big-endian (IBM POWER processor) target.
The decNumber package included in the DFPAL package has DECLITEND value set to 0. Additionally, respective Makefiles set DECLITEND to appropriate value on compiler command line.
|
DFPAL_THREAD_SAFE
|
Activate thread local storage for DFPAL context. This switch must be specified on all platforms to enable multi-threading support. Non multi-threaded application may get marginal performance benefit by not defining this switch. Absence of this switch bypasses a thread local storage. |
DFPAL_OS_AIX5L
DFPAL_OS_LOP
DFPAL_OS_WINDOWS
|
Specify target platform using one of these switches. Using DFPAL_OS_AIX5L implies detecting and
activating hardware decimal floating point with AIX on POWER6. Such code will run on any level of supported AIX operating system with any supported POWER processor. On pre-POWER6 processors, DFPAL will utilize decNumber for the decimal floating point arithmetic.
Using
Use |
DFPAL_USE_INTTYPES_H
DFPAL_LOCAL_INTTYPES
|
For C99 data types, some platform have inttypes.h , whereas others have stdint.h (e.g. AIX, Linux). Windows does not have either. Select appropriate switch for your platform. For Windows use DFPAL_LOCAL_INTTYPES switch. If your build environment does not work with any of these, create and
edit a file with stdint.h name and define appropriate data types.
|
DFPAL_INTEGER64_LITERAL_LL
DFPAL_INTEGER64_LITERAL_L
DFPAL_INTEGER64_LITERAL_i64
|
Various platforms/compilers use different literal designator for 64-bit integers. Set any one of these switch accordingly. The default is LL and ULL for signed integer and unsigned integer, respectively. AIX/XLC do not require any switch from this list.
DFPAL_INTEGER64_LITERAL_i64 is for Windows platforms.
The easiest way to determine the literal designator for particular compiler/platform is to look at system header file limits.h .
|
DFPAL_NO_HW_DFP
|
Use this switch if target platform/compiler does not support hardware DFP or #pragma mc_func
directives for the hardware instruction inline expansion (e.g. using GCC compiler on AIX). DFPAL compiled with this switch will only use decNumber for the DFP arithmetic even if running on POWER6.
|
DFPAL_USE_DECFLOAT
|
decFloat is new API, part of the decNumber package, which performs arithmetic directly on densely packed decimal (DPD) encoding. Use of decFloat eliminates DPD encoding to decNumber format conversion, and vice versa, enabling faster operation in software. Use of this switch has no impact on speed of hardware arithmetic operations. Use this switch to use decFloat instead of decNumber. More information about the decFloat is available at decNumber module. |
DFPAL_STANDALONE_DLL
(only for Windows) |
This switch is relevant to Windows platform only. DFPAL is
using pthread_once() facility on Unix platforms with POSIX thread support. Windows does not have equivalent facility. Alternatively, DFPAL is using DllMain() facility on Windows platform. Compile with this switch if DFPAL is being compiled as standalone library (Dynamic Link Library or DLL). If DFPAL is integrated into some container module such as EXE or another DLL, use that container module's DllMain() equivalent facility. The container module's DllMain() equivalent facility must call dfpalInitProcessContext() for DLL_PROCESS_ATTACH event. No other actions are necessary for the remaining events.A sample export symbol definition file dfpalsymexp.def is included for convenience.
|
DFPAL_USE_COMPILER_DFP
|
In future when application build environment is migrated to XLC version 9, this switch allows compiler native decimal floating point usage, bypassing DFPAL. Applications can take advantage of the fastest decimal floating point arithmetic using compile native decimal floating (as compared to the compiler native decimal floating point, all arithmetic operations have function call overhead with DFPAL). To be able to use this switch, application must use decNN...() macros rather than decimalNN...() functions (decNN...() directly map to either
decimalNN...() function call or equivalent compiler native decimal floating point operation).
|
xlc_r
is recommended when building DFPAL for multi-threaded environment.–qlongdouble
flag to direct 128-bit word length for long double
datatype, internally used by DFPAL.–qlongdouble
flag. There shall be no linking or runtime problems mixing such object codes. -O2
on AIX, with XLC compiler.-qflttrap
flag to enable floating point exception traps if application is using floating point exception traps (not a common practice). This flag is
not recommended if application does not rely on the floating point exception traps.Following is sample XLC command line on AIX (assumes application does not use floating point exception traps; add -qflttrap
flag to following command, otherwise).
xlc_r -c –q64 -O2 -DDFPAL_THREAD_SAFE -DDFPAL_OS_AIX5L -q64 -qlongdouble qflttrap -qlanglvl=stdc99 -I ../decNumber -I . dfpal.c
-mlong-double-128
flag to direct 128-bit word length for long double
datatype, internally used by DFPAL.-O3
for GCC and -O for IBM XLC on Linux on Power.Following is sample GCC command line on Linux on Power.
gcc -c -m64 -mlong-double-128 -O3 -DDFPAL_THREAD_SAFE -DDFPAL_OS_LOP -DDFPAL_INTEGER64_LITERAL_LL -I ../decNumber -I . dfpal.c
L
).
cc -c -DDFPAL_THREAD_SAFE -DDFPAL_NO_HW_DFP -DDFPAL_INTEGER64_LITERAL_L -I ../decNumber -I . dfpal.c
cl -c -DDFPAL_THREAD_SAFE -DDFPAL_NO_HW_DFP -DDFPAL_LOCAL_INTTYPES -DDFPAL_INTEGER64_LITERAL_i64 -DDFPAL_STANDALONE_DLL -I ../decNumber -I . dfpal.c
dfpalInit()
.
malloc()
for the application memory allocation. Instead, such applications have their own memory management layer based on shared memory, for example. This function shall be called before dfpalInit()
to determine amount of memory needed by the DFPAL.
dfpalInit()
before any of its service is accessed. The input context
is pointer to allocated memory. This function either returns DFPAL_ERR_NO_ERROR
or an error code indicating error condition. List of possible errors and error codes can be found in dfpalerr.h
. For multi-threaded application, each thread using DFPAL service must initialize using this service. Additionally, application is responsible for making sure that memory passed as an argument is thread safe.
dfpalInit()
reads environment variable DFPAL_EXE_MODE
. Possible values for this environment variable are DNSW
(force DFPAL to use decNumber software mode), PPCHW
(force DFPAL to use PowerPC hardware mode; dfpalInit()
will return error if no hardware support available), or AUTO
(auto detect). Default value, in absence of the environment variable or undefined value, is AUTO
.
dlopen()/dlsym()
. Applications not using runtime linking and loading do not have to use this.
dfpalInit()
call earlier. It takes a pointer to function performing memory de-allocation. Typically, memory de-allocation function is corresponding to one used to allocate memory for the dfpalInit()
.
DNSW
(decNumber Software) if DFPAL is using decNumber software implementation for the decimal floating point arithmetic. Returns PPCHW
(Power PC Hardware) if DFPAL is using hardware decimal floating point arithmetic.
dfpalGetError()
after this function call will return “No error”.
dfpalGetError()
but only returns DFPAL error code.
dfpalInit()
on Unix platforms. On Windows platform, if DFPAL is integrated into some other container module, use that container module’s DllMain()
equivalent facility to call dfpalInitProcessContext()
for DLL_PROCESS_ATTACH
event. Refer to How to compile DFPAL? for more details.
The following guidelines shall be observed with DFPAL.
DEC_Overflow
, DEC_Underflow
, and operating system defines such as FP_OVERFLOW, FP_UNDERFLOW
etc. (defined in fpxcp.h
).
"DFPAL_"
. For example, DFPAL_FP_OVERFLOW
and DFPAL_FP_UNDERFLOW
. DFPAL definition values are dynamic, changed at runtime depending on whether DFPAL is operating in hardware or software.
fp_clr_flag(), fp_set_flag(), fp_read_flag(), fp_swap_flag()
and so on). This will allow easy code migration to compiler native decimal floating point usage.
- DFPAL_FP_INVALID
- DFPAL_FP_OVERFLOW
- DFPAL_FP_UNDERFLOW
- DFPAL_FP_DIV_BY_ZERO
- DFPAL_FP_INEXACT
- DFPAL_FP_ALL
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
.
dfpalClearStatusFlag()
function with DFPAL_FP_ALL
argument.
mask
parameter. Bit value of 1 in the mask
will set that flag, value of 0 will clear the flag.
dfpalSetStatusFlag()
and the dfpalReadStatusFlag()
. Read and return current exception status flags, set exception status flags specified by the mask
parameter.
SIGFPE
is raised when trap is enabled for that particular exception.
- DFPAL_TRP_INVALID
- DFPAL_TRP_OVERFLOW
- DFPAL_TRP_UNDERFLOW
- DFPAL_TRP_DIV_BY_ZERO
- DFPAL_TRP_INEXACT
- DFPAL_TRP_ALL
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.
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.
mask
parameter is enabled, 0 otherwise.
- DFPAL_ROUND_TO_NEAREST_WITH_TIES_TO_EVEN
- DFPAL_ROUND_TOWARD_ZERO
- DFPAL_ROUND_TOWARD_POSITIVE_INFINITY
- DFPAL_ROUND_TOWARD_NEGATIVE_INFINITY
- DFPAL_ROUND_TO_NEAREST_WITH_TIES_AWAY_FROM_ZERO
- DFPAL_ROUND_TO_NEAREST_WITH_TIES_TOWARD_ZERO
- DFPAL_ROUND_AWAY_FROM_ZERO
rndmode
parameter.
rndmode
parameter.
Decimal floating point operations are classified into the following categories.
Programming NoteThis guide refers todecimalNN...() routines. However, it is highly recommended that application program to decNN...() macros for easy migration to compiler native decimal floating point using the DFPAL_USE_COMPILER_DFP compile time switch. Refer to How to compile DFPAL? for more information. The decNN...() macros are listed in square brackets.
Not all the facilities listed below is a part of the current Extension for the programming language C to support decimal floating-point arithmetic working draft technical report by the ISO/IEC JTC1 SC22 WG14 committee. The proposal for extension is continuously evolving. Refer to the current draft of the proposal for extension. Adhering to the facilities listed in the proposal for extension may simplify migration to compiler native decimal floating point usage later. |
rhs
from decimalNN to equivalent string representation, populate memory location pointed by the out
parameter. Returns same memory location as out
. Memory must be pre-allocated by application.
dfpstr
into decimalNN number. Exceptions are raised as discussed in General Decimal Arithmetic Specification.
rhs
to binary floating point double representation. There will be lost precision and/or slight inaccuracy converting between these representations. Input sNaN
is converted to NaN
, because double value of sNaN
is not portable.
rhs
in packed binary coded decimal (BCD) string. The bcdOutLen
is length of the input array bcdOut
. Then length must be at least 9 bytes (for decimal64
) or 18 bytes (for decimal128
), otherwise unchanged bcdOut
is returned. The scale
is output – scale of the rhs
. The output array will be populated in right aligned order. That is, highest array index will hold least significant digit nibble and a sign nibble. Application must pre-allocated enough memory for the bcdOut
, and clear the array content if necessary. Output sign is C
(for +ve number) or D
(for –ve number).
bcdIn
into decimalNN number, return decimalNN. The bcdInLen
is length of input array bcdIn
. The length must be at least 9 bytes (for decimal64) or 18 bytes (for decimal128), or NaN is returned. The input scale
is used to set exponent of the output number. The input bcdIn
is assumed to be right aligned. That is, highest array index will hold least significant nibble and a sign nibble. Input sign nibble must be present, and it is assumed to be C
(for +ve number) or D
(for –ve number). When the input array in larger than 9 bytes (for decimal64) or 18 bytes (for decimal128), no more than 16 digits (for decimal64) or 34 digits (for decimal128) shall be present. Application can pre-process input array before passing it to the decimalNNFromPackedBCD()
to ensure that above rules are observed. This rules are imposed to reconcile rounding effect between hardware and software implementations of the decimal floating point.
rhs
into decimal32 format. In case of lost precision INEXACT
exception is raised. Note: this function is intended to be used for decimal32 arithmetic emulation. The INVALID
exception is not raised on sNaN input to avoid any side effect.
rhs
into decimal64 format. No exceptions are possible. Note: this function is intended to be used for decimal32 arithmetic emulation. The INVALID
exception is not raised on sNaN input to avoid any side effect.
General integer conversion rulesFor conversion to integer, noINEXACT exception is raised even if there are lost digit(s). Conversion to integer is not performed with current rounding mode, rounding mode is always truncate. (Conversion to integer with desired rounding mode can be performed by using decimalNNToIntegralValue() function followed by either decimalNNToIntXX() or decimalNNToUintXX() conversion.).
For out of bound or Infinite input that cannot be represented in the destination format, an integer with largest magnitude in the direction of the sign with the same sign as source (input) is returned with INVALID exception raised. For example, converting decimalNN to 64-bit signed integer, an input of +Infinite (or say 1E+100) will return 9223372036854775807 , -Infinite (or say -1E+100) will return -9223372036854775808 , The INVALID exception is raised in either case.
For +/-sNaN or +/-NaN input smallest possible integer is returned, regardless of the source (input) sign. For example, converting decimalNN value +NaN to 64-bit signed integer, return value is -9223372036854775808 regardless of the input sign. The INVALID exception raised.
Negative source (input) is considered out of bound value for unsigned integer conversion, largest magnitude in the direction of the –ve sign is 0 for the unsigned integer. Similarly, smallest possible integer, which is 0 is returned for +/-NaN or +/-sNaN input with INVALID exception raised.
In case of conversion from integer to decimalNN, current rounding mode is used and INEXACT exception may be raised, especially when converting 64-bit integer to decimal64. Because maximum precision for decimal64 is 16 digits and integer may need up to 20 digits for exact representation. No other exceptions are possible.
|
rhs
to equivalent 64-bit signed integer value. The general integer conversion rules apply. The output 64-bit signed integer is in range [-9223372036854775808, 9223372036854775807]
.
rhs
to equivalent 64-bit unsigned integer value. The general integer conversion rules apply. The output 64-bit unsigned integer is in range [0, 18446744073709551615]
.
rhs
to equivalent 32-bit signed integer value. The general integer conversion rules apply. The output 32-bit signed integer is in range [-2147483648, 2147483647]
.
rhs
to equivalent 32-bit unsigned integer value. The general integer conversion rules apply. The output 32-bit unsigned integer is in range [0, 4294967295]
.
rhs
to equivalent decimalNN format. The general integer conversion rules apply.
rhs
to equivalent decimalNN format. The general integer conversion rules apply.
rhs
to equivalent decimalNN format. The general integer conversion rules apply.
rhs
to equivalent decimalNN format. The general integer conversion rules apply.
rhs
. Returns integer non-zero value (boolean 1) if rhs
is –ve, 0 otherwise.
rhs
.
rhs
.
rhs
is +/-Infinite, 0 otherwise.
rhs
is either +/-qNaN or +/-sNaN, 0 otherwise.
rhs
is +/-qNaN, 0 otherwise.
rhs
is +/-sNaN, 0 otherwise.
rhs
is –ve number, 0 otherwise. This function is similar to the decNNSign()
.
rhs
numeric value is +/-0, 0 otherwise.
rhs
. That is, if the number has any fractional trailing zeros they are removed by dividing the coefficient by the appropriate power of ten and adjusting the exponent accordingly.
rhs
.
rhs
.
rhs
.
lsh
and rhs
, return result of the add operation.
lsh
and rhs
, return decmimalNN –1 if lsh
is less than rhs
, decimalNN 0 if lsh
is equal to rhs
, and decmimalNN +1 if lsh
is greater than rhs
.
lsh
and rhs
, return boolean 1 if lsh
is less than rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompare()
for use in programming language conditional constructs such as if
, for
or while
statement.
lsh
and rhs
, return boolean 1 if lsh
is less than or equal to rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompare()
for use in programming language conditional constructs such as if
, for
or while
statement.
lsh
and rhs
, return boolean 1 if lsh
is equal to rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompare()
for use in programming language conditional constructs such as if
, for
or while
statement.
lsh
and rhs
, return boolean 1 if lsh
is not equal to rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompare()
for use in programming language conditional constructs such as if
, for
or while
statement.
lsh
and rhs
, return boolean 1 if lsh
is greater than rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompare()
for use in programming language conditional constructs such as if
, for
or while
statement.
lsh
and rhs
, return boolean 1 if lsh
is greater than or equal to rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompare()
for use in programming language conditional constructs such as if
, for
or while
statement.
lsh
and rhs
, return decmimalNN –1 if lsh
is less than rhs
, decimalNN 0 if lsh
is equal to rhs
, and decmimalNN +1 if lsh
is greater than rhs
. Unlike, regular compare, compare Total compares numbers using abstract representation. Refer to Decimal Arithmetic Specification for more details.
lsh
and rhs
using total order, return boolean 1 if lsh
is less than rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompareTotal()
for use in programming language conditional constructs such as if
, for
or while
statement.
lsh
and rhs
using total order, return boolean 1 if lsh
is less than or equal to rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompareTotal()
for use in programming language conditional constructs such as if
, for
or while
statement.
lsh
and rhs
using total order, return boolean 1 if lsh
is equal to rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompareTotal()
for use in programming language conditional constructs such as if
, for
or while
statement.
lsh
and rhs
using total order, return boolean 1 if lsh
is not equal to rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompareTotal()
for use in programming language conditional constructs such as if
, for
or while
statement.
lsh
and rhs
using total order, return boolean 1 if lsh
is greater than rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompareTotal()
for use in programming language conditional constructs such such as if
, for
or while
statement.
lsh
and rhs
using total order, return boolean 1 if lsh
is greater than or equal to rhs
. This macro is convenient, fast and it is recommended over the decimalNNCompareTotal()
for use in programming language conditional constructs such such as if
, for
or while
statement.
lsh
with rhs
, return result.
lsh
with rhs
, return integer part of the quotient.
rhs
. Refer to decNumber module for more information.
rhs
. Refer to decNumber module for more information.
rhs
. Refer to decNumber module for more information.
lsh
and rhs
. Note that regular numeric comparison operation is used.
lsh
and rhs
. Note that regular numeric comparison operation is used.
rhs
. This can be used as unary negate operation.
lsh
and rhs
, return result of the multiply operation.
rhs
, derived from the rhs
by removing trailing zeros in the coefficient. Zeros removed by dividing the coefficient by the appropriate power of ten and adjusting the exponent accordingly.
rhs
. This function essentially no-op, provided for identity with the decimalNNMinus()
.
lhs
to the power of the rhs
. Refer to decNumber module for more information.
decimalNNPower()
, however the second argument rhs
is integer. Useful for square, or cube of the lhs
.
lhs
so that its exponent has a specific value, equal to that of the rhs
. The decimalNNRescale()
function may also be used for this purpose, but requires the exponent to be given as a decimal number.
lhs
is divided by the rhs
.
lhs
is divided by the rhs, using the rules defined in IEEE 854. This follows the same definition as decimalNNRemainder()
, except that the nearest integer (or the nearest even integer if the remainder is equidistant from two) is used for the quotient instead of the result from decimalNNDivideInteger()
.
lhs
had the value 10 and rhs
had the value 6 then the result would be -2 (instead of 4) because the nearest multiple of 6 is 12 (rather than 6).
decimalNNQuantize()
, however, the second argument rhs
specifies new exponent. The rhs
must be a whole number (before any rounding); that is, any digits in the fractional part of the number must be zero. decimalNNQuantize()
is faster and it is recommended over decimalNNRescale()
. This function may be removed from the future release.
lhs
and rhs
have equal exponent. Return 0, otherwise.
rhs
.
lsh
and rhs
, return result of the subtract operation.
decimalNNToInt...()
, the result may have a positive exponent.
rhs
. No exceptions, not even INEXACT
, are raised (unless the operand is sNaN). The result may have a positive exponent.
rhs
. No exceptions, not even INEXACT
, are raised (unless the operand is sNaN). The result may have a positive exponent.
DECDPUN
and DECBUFFER
. However, beginning decNumber version 3.40, the DECLITEND
must be set 1, if the target platform is little-endian, or 0, if the target platform is big-endian. Refer to How to compile DFPAL? for more information.
dfpalInit()
.
DECBUFFER
unchanged from its default value, decNumber should not allocate any memory either. Additionally, consider using decFloat based arithmetic, which is much faster and does not allocate any memory. Refer to How to compile DFPAL? for more information.
DFPAL_THREAD_SAFE
compile time switch. Refer to How to compile DFPAL? for more details.
DFPAL_EXE_MODE
to either DNSW
(decNumber software) or PPCHW
(PowerPC hardware) to force DFPAL to use particular execution mode. The DNSW
mode will work on all cases, however DFPAL initialization will fail when using PPCHW
on architecture where it is not possible. Refer to DFPAL management functions for more information.
decNN...()
macros in association with DFPAL_USE_COMPILER_DFP
compile time switch bypasses DFPAL and uses compiler native decimal floating point. Refer to How to compile DFPAL? for more information.
DFPAL_USE_DECFLOAT
must be defined to activate decFloat at compile time.
dfpalInit()
. The dfpalInit()
will fail if decNumber or decFloat is not compiled with correct endian settings.
dfpalClearAllStatusFlag()
is added to improve performance.
decimalNNFromPackedBCD()
has different semantics as compared to previous release.
strtod()/snprintf()
. The strtod()/snprintf()
behavior in terms of raising floating point exception is not consistent across platforms. Applications should not assume presence or absence of particular floating point exception after these conversions.
strtod()/snprintf()
(rounding mode is not shared by binary floating point and decimal floating point for POWER6 processor). Application's preference for particular rounding mode for the binary floating conversions [strtod()/snprintf()
] can be implemented by using a wrapper around the decimalNN{To|From}Double()
routines to set binary floating point rounding mode before calling the conversion routines.
strtod()/snprintf()
are implemented with slightly different semantics.
decimalNNRescale()
function, it may be removed from the future release. Use decimalNNQuantize()
instead. Due to exponent clamp in the hardware, results are not guaranteed when input number's exponent is close to Emax or Emin.
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. |