Oracle® Solaris Studio 12.4: C User's Guide

Exit Print View

Updated: March 2015
 
 

2.19.2 Decimal Floating-Point Intrinsics

SPARC64X and SPARC64X+ support the Decimal Floating-Point data type and operations. The data format conforms to 64bit DPD defined in IEEE 754-2008. The compiler provides the type and various functions to handle the data.

2.19.2.1 Types and Operations

To represent Decimal Floating-Point numbers, _Decimal64 intrinsic type is declared in dpd_conf.h. You must include the header file prior to use of the type as in the following example:

#include <dpd_conf.h>
int main(void) {
  _Decimal64 dd;
  ...
  return 0;
}

_Decimal64 type

  • can be modified with type modifiers: const and/or volatile.

  • can be specified with storage class specifiers: auto, static, register, extern and/or typedef.

  • can be an element of an aggregate: array, struct and/or union.

_Decimal64 type variables

  • can be a formal parameter of a function.

  • can be an actual argument of a function call.

  • can be the return value of a function.

  • can be lhs or rhs of assignment operator "=".

  • can be the operand of address operator "&".

  • can be the operand of sizeof operator.

  • can be the operand of typeof operator.

Intrinsic functions are provided for other operations such as arithmetic, comparison, or type conversion.

Literal syntax for _Decimal64 is not supported. Intrinsics for type conversion can be used instead.

Memory alignment of an _Decimal64 type data is the same as a 64-bit Binary Floating-Point number.

2.19.2.2 Macros and Pragmas

The __DEC_FP_INTR macro is defined as 1 when -xarch=[sparcace|sparcaceplus] and -m64 are specified. This macro is useful to determine whether the compiler supports the Decimal Floating-Point intrinsics feature.

The DEC_EVAL_METHOD macro required by IEEE 754-2008 is defined as 1 when dpd_conf.h is included.

The __STDC_DEC_FP__ macro is not defined, as the compiler does not fully support the functionality described in ISO/IEC TR 24732.

The #pragma FLOAT_CONST_DECIMAL_64 required by IEEE 754-2008 is not supported.

2.19.2.3 Intrinsic functions

Intrinsic functions listed below are declared in dpd_conf.h. They are useful to operate _Decimal64 type variables.

void __dpd64_store(const _Decimal64 src, _Decimal64 * const addr)

This function stores src into memory addressed by addr. addr must be aligned on an 8-byte boundary, or the behavior is undefined regardless of the -xmemalign setting.

_Decimal64 __dpd64_load(const _Decimal64 * const addr)

This function loads _Decimal64 type value from memory addressed by addr, and returns it. addr must be aligned on an 8-byte boundary, or the behavior is undefined regardless of the -xmemalign setting.

_Decimal64 __dpd64_add(_Decimal64 src1, _Decimal64 src2)

This function adds src1 and src2, and returns the result. A floating-point exception is thrown in accordance with the IEEE 754-2008 standard.

_Decimal64 __dpd64_sub(_Decimal64 src1, _Decimal64 src2)

This function subtracts src2 from src1, and returns the result. A floating-point exception is thrown in accordance with the IEEE 754-2008 standard.

_Decimal64 __dpd64_mul(_Decimal64 src1, _Decimal64 src2)

This function multiplies src1 and src2, and returns the result. A floating-point exception is thrown in accordance with the IEEE 754-2008 standard.

_Decimal64 __dpd64_div(_Decimal64 src1, _Decimal64 src2)

This function divides src1 by src2, and returns the result. A floating-point exception is thrown in accordance with the IEEE 754-2008 standard.

_Decimal64 __dpd64_abs(_Decimal64 src)

This function computes the absolute value of src and returns the result. No floating-point exception is thrown even if src is signaling NaN.

_Decimal64 __dpd64_neg(_Decimal64 src)

This function reverses the sign of src and returns the result. No floating-point exception is thrown even if src is signaling NaN.

int __dpd64_cmpeq(_Decimal64 src1, _Decimal64 src2)

This function returns non-0 when src1 is equal to src2, otherwise it returns 0. The treatments of NaN, Inf and negative-Zero conforms to IEEE 754-2008.

int __dpd64_cmpne(_Decimal64 src1, _Decimal64 src2)

This function returns non-0 when src1 is not equal to src2, otherwise it returns 0. The treatments of NaN, Inf and negative-Zero conforms to IEEE 754-2008.

int __dpd64_cmpgt(_Decimal64 src1, _Decimal64 src2)

This function returns non-0 when src1 is grater than src2, otherwise it returns 0. The treatments of NaN, Inf and negative-Zero conforms to IEEE 754-2008.

int __dpd64_cmpge(_Decimal64 src1, _Decimal64 src2)

This function returns non-0 when src1 is grater than or equal to src2, otherwise it returns 0. The treatments of NaN, Inf and negative-Zero conforms to IEEE 754-2008.

int __dpd64_cmplt(_Decimal64 src1, _Decimal64 src2)

This function returns non-0 when src1 is less than src2, otherwise it returns 0. The treatments of NaN, Inf and negative-Zero conforms to IEEE 754-2008.

int __dpd64_cmple(_Decimal64 src1, _Decimal64 src2)

This function returns non-0 when src1 is less than or equal to src2, otherwise it returns 0. The treatments of NaN, Inf and negative-Zero conforms to IEEE 754-2008.

_Decimal64 __dpd64_convert_from_int64(int64_t src)

This function converts a 64-bit signed integer value in src to a Decimal Floating-Point value and returns the result.

_Decimal64 __dpd64_convert_from_uint64(uint64_t src)

This function converts a 64-bit unsigned integer value in src to a Decimal Floating-Point value and returns the result.

_Decimal64 __dpd64_convert_from_double(double src)

This function converts a Binary Floating-Point value in src to a Decimal Floating-Point value and returns the result.

int64_t __dpd64_convert_to_int64(_Decimal64 src)

This function converts a Decimal Floating-Point value in src to a 64-bit signed integer value and returns the result.

uint64_t __dpd64_convert_to_uint64(_Decimal64 src)

This function converts a Decimal Floating-Point value in src to a 64-bit unsigned integer value and returns the result.

double __dpd64_convert_to_double(_Decimal64 src)

This function converts a Decimal Floating-Point value in src to a Binary Floating-Point value and returns the result.

int __dpd_getround(void)

This function retrieves the current rounding mode for _Decimal64. The value is defined in dpd_conf.h, as follows:

__DPD_ROUND_NEAREST

round to nearest, ties to even

__DPD_ROUND_TOZERO

round toward zero

__DPD_ROUND_POSITIVE

round toward positive infinity

__DPD_ROUND_NEGATIVE

round toward negative infinity

__DPD_ROUND_NEARESTFROMZERO

round to nearest, ties away from zero

The initial value of the rounding mode for _Decimal64 is __DPD_ROUND_NEAREST. Note that the -fround option does not alter the rounding mode for _Decimal64.

int __dpd_setround(int r)

This function set the rounding mode for _Decimal64 to r. r should be one those listed above. It returns 0 on success or non-0 on failure.