Quick Links:

bal | bbl | bdl | bsl

Static Public Member Functions

bdldfp::DecimalConvertUtil Struct Reference

#include <bdldfp_decimalconvertutil.h>

List of all members.

Static Public Member Functions

static double decimal32ToDouble (Decimal32 decimal)
static double decimal64ToDouble (Decimal64 decimal)
static double decimal128ToDouble (Decimal128 decimal)
static double decimalToDouble (Decimal32 decimal)
static double decimalToDouble (Decimal64 decimal)
static double decimalToDouble (Decimal128 decimal)
static float decimal32ToFloat (Decimal32 decimal)
static float decimal64ToFloat (Decimal64 decimal)
static float decimal128ToFloat (Decimal128 decimal)
static float decimalToFloat (Decimal32 decimal)
static float decimalToFloat (Decimal64 decimal)
static float decimalToFloat (Decimal128 decimal)
static Decimal32 decimal32FromDouble (double binary, int digits=0)
static Decimal32 decimal32FromFloat (float binary, int digits=0)
static Decimal64 decimal64FromDouble (double binary, int digits=0)
static Decimal64 decimal64FromFloat (float binary, int digits=0)
static Decimal128 decimal128FromDouble (double binary, int digits=0)
static Decimal128 decimal128FromFloat (float binary, int digits=0)
static void decimal32ToDPD (unsigned char *buffer, Decimal32 decimal)
static void decimal64ToDPD (unsigned char *buffer, Decimal64 decimal)
static void decimal128ToDPD (unsigned char *buffer, Decimal128 decimal)
static void decimalToDPD (unsigned char *buffer, Decimal32 decimal)
static void decimalToDPD (unsigned char *buffer, Decimal64 decimal)
static void decimalToDPD (unsigned char *buffer, Decimal128 decimal)
static Decimal32 decimal32FromDPD (const unsigned char *buffer)
static Decimal64 decimal64FromDPD (const unsigned char *buffer)
static Decimal128 decimal128FromDPD (const unsigned char *buffer)
static void decimal32FromDPD (Decimal32 *decimal, const unsigned char *buffer)
static void decimal64FromDPD (Decimal64 *decimal, const unsigned char *buffer)
static void decimal128FromDPD (Decimal128 *decimal, const unsigned char *buffer)
static void decimalFromDPD (Decimal32 *decimal, const unsigned char *buffer)
static void decimalFromDPD (Decimal64 *decimal, const unsigned char *buffer)
static void decimalFromDPD (Decimal128 *decimal, const unsigned char *buffer)
static void decimal32ToBID (unsigned char *buffer, Decimal32 decimal)
static void decimal64ToBID (unsigned char *buffer, Decimal64 decimal)
static void decimal128ToBID (unsigned char *buffer, Decimal128 decimal)
static void decimalToBID (unsigned char *buffer, Decimal32 decimal)
static void decimalToBID (unsigned char *buffer, Decimal64 decimal)
static void decimalToBID (unsigned char *buffer, Decimal128 decimal)
static Decimal32 decimal32FromBID (const unsigned char *buffer)
static Decimal64 decimal64FromBID (const unsigned char *buffer)
static Decimal128 decimal128FromBID (const unsigned char *buffer)
static void decimal32FromBID (Decimal32 *decimal, const unsigned char *buffer)
static void decimal64FromBID (Decimal64 *decimal, const unsigned char *buffer)
static void decimal128FromBID (Decimal128 *decimal, const unsigned char *buffer)
static void decimalFromBID (Decimal32 *decimal, const unsigned char *buffer)
static void decimalFromBID (Decimal64 *decimal, const unsigned char *buffer)
static void decimalFromBID (Decimal128 *decimal, const unsigned char *buffer)
static unsigned char * decimal32ToNetwork (unsigned char *buffer, Decimal32 decimal)
static unsigned char * decimal64ToNetwork (unsigned char *buffer, Decimal64 decimal)
static unsigned char * decimal128ToNetwork (unsigned char *buffer, Decimal128 decimal)
static unsigned char * decimalToNetwork (unsigned char *buffer, Decimal32 decimal)
static unsigned char * decimalToNetwork (unsigned char *buffer, Decimal64 decimal)
static unsigned char * decimalToNetwork (unsigned char *buffer, Decimal128 decimal)
static const unsigned char * decimal32FromNetwork (Decimal32 *decimal, const unsigned char *buffer)
static const unsigned char * decimal64FromNetwork (Decimal64 *decimal, const unsigned char *buffer)
static const unsigned char * decimal128FromNetwork (Decimal128 *decimal, const unsigned char *buffer)
static const unsigned char * decimalFromNetwork (Decimal32 *decimal, const unsigned char *buffer)
static const unsigned char * decimalFromNetwork (Decimal64 *decimal, const unsigned char *buffer)
static const unsigned char * decimalFromNetwork (Decimal128 *decimal, const unsigned char *buffer)
static bsls::Types::size_type decimal64ToMultiWidthEncoding (unsigned char *buffer, bdldfp::Decimal64 decimal)
static bsls::Types::size_type decimal64ToMultiWidthEncodingRaw (unsigned char *buffer, bdldfp::Decimal64 decimal)
static Decimal64 decimal64FromMultiWidthEncodingRaw (const unsigned char *buffer, bsls::Types::size_type size)
static bool isValidMultiWidthSize (bsls::Types::size_type size)
static Decimal64 decimal64FromMultiWidthEncoding (const unsigned char *buffer, bsls::Types::size_type size)
static int decimal64FromMultiWidthEncodingIfValid (Decimal64 *decimal, const unsigned char *buffer, bsls::Types::size_type size)
static unsigned char * decimal64ToVariableWidthEncoding (unsigned char *buffer, bdldfp::Decimal64 decimal)
static const unsigned char * decimal64FromVariableWidthEncoding (bdldfp::Decimal64 *decimal, const unsigned char *buffer)

Detailed Description

This struct provides a namespace for utility functions that convert between the decimal floating-point types of bdldfp_decimal and various other formats.

See Component bdldfp_decimalconvertutil


Member Function Documentation

static double bdldfp::DecimalConvertUtil::decimal32ToDouble ( Decimal32  decimal  )  [static]
static double bdldfp::DecimalConvertUtil::decimal64ToDouble ( Decimal64  decimal  )  [static]
static double bdldfp::DecimalConvertUtil::decimal128ToDouble ( Decimal128  decimal  )  [static]

[!DEPRECATED!] Use deciamalToDouble instead.

static double bdldfp::DecimalConvertUtil::decimalToDouble ( Decimal32  decimal  )  [static]
static double bdldfp::DecimalConvertUtil::decimalToDouble ( Decimal64  decimal  )  [static]
static double bdldfp::DecimalConvertUtil::decimalToDouble ( Decimal128  decimal  )  [static]

Return a double object having the value closest to the value of the specified decimal object following the conversion rules defined by IEEE-754:

  • If the decimal object is a NaN, return a NaN.
  • Otherwise if decimal is positive or negative infinity, return infinity of the same sign.
  • Otherwise if decimal is positive or negative zero, return zero of the same sign.
  • Otherwise if decimal object has an absolute value that is larger than std::numeric_limits<double>max(), raise the "overflow" floating-point exception and return infinity of the same sign as decimal.
  • Otherwise if decimal has an absolute value that is smaller than std::numeric_limits<double>min(), raise the "underflow" floating-point exception and return zero of the same sign as decimal.
  • Otherwise if decimal has a value that has more significant base-10 digits than std::numeric_limits<double>digits10, raise the "inexact" floating-point exception, round that value according to the binary rounding direction setting of the floating-point environment, and return the result of that.
  • Otherwise if decimal has a significand that cannot be exactly represented using binary floating-point, raise the "inexact" floating-point exception, round that value according to the binary rounding direction setting of the environment, and return the result of that.
  • Otherwise use the exact value of the other object for the initialization if this object.
static float bdldfp::DecimalConvertUtil::decimal32ToFloat ( Decimal32  decimal  )  [static]
static float bdldfp::DecimalConvertUtil::decimal64ToFloat ( Decimal64  decimal  )  [static]
static float bdldfp::DecimalConvertUtil::decimal128ToFloat ( Decimal128  decimal  )  [static]

[!DEPRECATED!] Use deciamalToFloat instead.

static float bdldfp::DecimalConvertUtil::decimalToFloat ( Decimal32  decimal  )  [static]
static float bdldfp::DecimalConvertUtil::decimalToFloat ( Decimal64  decimal  )  [static]
static float bdldfp::DecimalConvertUtil::decimalToFloat ( Decimal128  decimal  )  [static]

Return a float object having the value closest to the value of the specified decimal object following the conversion rules defined by IEEE-754:

  • If the decimal object is a NaN, return a NaN.
  • Otherwise if decimal is positive or negative infinity, return infinity of the same sign.
  • Otherwise if decimal is positive or negative zero, return zero of the same sign.
  • Otherwise if decimal object has an absolute value that is larger than std::numeric_limits<long double>max(), raise the "overflow" floating-point exception and return infinity of the same sign as decimal.
  • Otherwise if decimal has an absolute value that is smaller than std::numeric_limits<float>min(), raise the "underflow" floating-point exception and return zero of the same sign as decimal.
  • Otherwise if decimal has a value that has more significant base-10 digits than std::numeric_limits<float>digits10, raise the "inexact" floating-point exception, round that value according to the binary rounding direction setting of the floating-point environment, and return the result of that.
  • Otherwise if decimal has a significand that cannot be exactly represented using binary floating-point, raise the "inexact" floating-point exception, round that value according to the binary rounding direction setting of the environment, and return the result of that.
  • Otherwise use the exact value of the other object for the initialization if this object.
static Decimal32 bdldfp::DecimalConvertUtil::decimal32FromDouble ( double  binary,
int  digits = 0 
) [static]
static Decimal32 bdldfp::DecimalConvertUtil::decimal32FromFloat ( float  binary,
int  digits = 0 
) [static]
static Decimal64 bdldfp::DecimalConvertUtil::decimal64FromDouble ( double  binary,
int  digits = 0 
) [static]
static Decimal64 bdldfp::DecimalConvertUtil::decimal64FromFloat ( float  binary,
int  digits = 0 
) [static]
static Decimal128 bdldfp::DecimalConvertUtil::decimal128FromDouble ( double  binary,
int  digits = 0 
) [static]
static Decimal128 bdldfp::DecimalConvertUtil::decimal128FromFloat ( float  binary,
int  digits = 0 
) [static]

Return a decimal floating-point number converted from the specified binary.

If binary is singular (+/-NaN, +/-Inf, or +/-0) or is not within the representable range of the return type, return a corresponding decimal singular value.

Optionally specify digits to indicate the number of significant digits to produce in the returned value. The digits parameter is treated as follows:

If digits is larger than the number of digits in the destination type, it will be reduced to that number of digits.

If digits is positive, the result is binary rounded to that many significant digits.

If digits is negative, the decimal value with the fewest significant digits that converts back to binary is returned if possible, and otherwise the value closest to binary is returned. Note that this provides the most visually appealing result but is the most expensive to compute.

If digits is not specified or 0, a default value will be used (possibly depending on the value of binary) based on the premise that binary is a converted decimal value of no more significant digits than is guaranteed to have a uniquely converted binary value (15 for double, 6 for float in general, and 7 for float in the range [ .0009999995 .. 8589972000 ]). Note that this is likely to have the best performance for "business" numbers (i.e., numbers that originate as decimal values in external market quote feeds).

Note that the purpose of these functions is to restore a decimal value that has been converted to a binary floating-point type. It is more efficient to use conversion constructors when all that is needed is the nearest decimal to the binary value.

Note that if binary is a float value that was converted from an IBM/Perkin-Elmer/Interdata binary float value itself converted from a decimal value of no more than 6 significant digits, specifying 6 for digits will recover the original decimal value. Not specifying digits may result in a value having a spurious seventh digit.

static void bdldfp::DecimalConvertUtil::decimal32ToDPD ( unsigned char *  buffer,
Decimal32  decimal 
) [static]
static void bdldfp::DecimalConvertUtil::decimal64ToDPD ( unsigned char *  buffer,
Decimal64  decimal 
) [static]
static void bdldfp::DecimalConvertUtil::decimal128ToDPD ( unsigned char *  buffer,
Decimal128  decimal 
) [static]
static void bdldfp::DecimalConvertUtil::decimalToDPD ( unsigned char *  buffer,
Decimal32  decimal 
) [static]
static void bdldfp::DecimalConvertUtil::decimalToDPD ( unsigned char *  buffer,
Decimal64  decimal 
) [static]
static void bdldfp::DecimalConvertUtil::decimalToDPD ( unsigned char *  buffer,
Decimal128  decimal 
) [static]

Populate the specified buffer with the Densely Packed Decimal (DPD) representation of the specified decimal value. The DPD representations of Decimal32, Decimal64, and Decimal128 require 4, 8, and 16 bytes respectively. The behavior is undefined unless buffer points to a contiguous sequence of at least sizeof(decimal) bytes. Note that the DPD representation is defined in section 3.5 of IEEE 754-2008.

static Decimal32 bdldfp::DecimalConvertUtil::decimal32FromDPD ( const unsigned char *  buffer  )  [static]
static Decimal64 bdldfp::DecimalConvertUtil::decimal64FromDPD ( const unsigned char *  buffer  )  [static]
static Decimal128 bdldfp::DecimalConvertUtil::decimal128FromDPD ( const unsigned char *  buffer  )  [static]

Return the native implementation representation of the value of the same size base-10 floating-point value stored in Densely Packed Decimal format at the specified buffer address. The behavior is undefined unless buffer points to a memory area at least sizeof(decimal) in size containing a value in DPD format.

static void bdldfp::DecimalConvertUtil::decimal32FromDPD ( Decimal32 decimal,
const unsigned char *  buffer 
) [static]
static void bdldfp::DecimalConvertUtil::decimal64FromDPD ( Decimal64 decimal,
const unsigned char *  buffer 
) [static]
static void bdldfp::DecimalConvertUtil::decimal128FromDPD ( Decimal128 decimal,
const unsigned char *  buffer 
) [static]
static void bdldfp::DecimalConvertUtil::decimalFromDPD ( Decimal32 decimal,
const unsigned char *  buffer 
) [static]
static void bdldfp::DecimalConvertUtil::decimalFromDPD ( Decimal64 decimal,
const unsigned char *  buffer 
) [static]
static void bdldfp::DecimalConvertUtil::decimalFromDPD ( Decimal128 decimal,
const unsigned char *  buffer 
) [static]

Store, into the specified decimal, the native implementation representation of the value of the same size base-10 floating point value represented in Densely Packed Decimal format, at the specified buffer address. The behavior is undefined unless buffer points to a memory area at least sizeof(decimal) in size containing a value in DPD format.

static void bdldfp::DecimalConvertUtil::decimal32ToBID ( unsigned char *  buffer,
Decimal32  decimal 
) [static]
static void bdldfp::DecimalConvertUtil::decimal64ToBID ( unsigned char *  buffer,
Decimal64  decimal 
) [static]
static void bdldfp::DecimalConvertUtil::decimal128ToBID ( unsigned char *  buffer,
Decimal128  decimal 
) [static]
static void bdldfp::DecimalConvertUtil::decimalToBID ( unsigned char *  buffer,
Decimal32  decimal 
) [static]
static void bdldfp::DecimalConvertUtil::decimalToBID ( unsigned char *  buffer,
Decimal64  decimal 
) [static]
static void bdldfp::DecimalConvertUtil::decimalToBID ( unsigned char *  buffer,
Decimal128  decimal 
) [static]

Populate the specified buffer with the Binary Integer Decimal (BID) representation of the specified decimal value. The BID representations of Decimal32, Decimal64, and Decimal128 require 4, 8, and 16 bytes respectively. The behavior is undefined unless buffer points to a contiguous sequence of at least sizeof(decimal) bytes. Note that the BID representation is defined in section 3.5 of IEEE 754-2008.

static Decimal32 bdldfp::DecimalConvertUtil::decimal32FromBID ( const unsigned char *  buffer  )  [static]
static Decimal64 bdldfp::DecimalConvertUtil::decimal64FromBID ( const unsigned char *  buffer  )  [static]
static Decimal128 bdldfp::DecimalConvertUtil::decimal128FromBID ( const unsigned char *  buffer  )  [static]

Return the native implementation representation of the value of the same size base-10 floating-point value stored in Binary Integer Decimal format at the specified buffer address. The behavior is undefined unless buffer points to a memory area at least sizeof(decimal) in size containing a value in BID format.

static void bdldfp::DecimalConvertUtil::decimal32FromBID ( Decimal32 decimal,
const unsigned char *  buffer 
) [static]
static void bdldfp::DecimalConvertUtil::decimal64FromBID ( Decimal64 decimal,
const unsigned char *  buffer 
) [static]
static void bdldfp::DecimalConvertUtil::decimal128FromBID ( Decimal128 decimal,
const unsigned char *  buffer 
) [static]
static void bdldfp::DecimalConvertUtil::decimalFromBID ( Decimal32 decimal,
const unsigned char *  buffer 
) [static]
static void bdldfp::DecimalConvertUtil::decimalFromBID ( Decimal64 decimal,
const unsigned char *  buffer 
) [static]
static void bdldfp::DecimalConvertUtil::decimalFromBID ( Decimal128 decimal,
const unsigned char *  buffer 
) [static]

Store, into the specified decimal, the native implementation representation of the value of the same size base-10 floating point value represented in Binary Integer Decimal format, at the specified buffer address. The behavior is undefined unless buffer points to a memory area at least sizeof(decimal) in size containing a value in BID format.

static unsigned char* bdldfp::DecimalConvertUtil::decimal32ToNetwork ( unsigned char *  buffer,
Decimal32  decimal 
) [static]
static unsigned char* bdldfp::DecimalConvertUtil::decimal64ToNetwork ( unsigned char *  buffer,
Decimal64  decimal 
) [static]
static unsigned char* bdldfp::DecimalConvertUtil::decimal128ToNetwork ( unsigned char *  buffer,
Decimal128  decimal 
) [static]
static unsigned char* bdldfp::DecimalConvertUtil::decimalToNetwork ( unsigned char *  buffer,
Decimal32  decimal 
) [static]
static unsigned char* bdldfp::DecimalConvertUtil::decimalToNetwork ( unsigned char *  buffer,
Decimal64  decimal 
) [static]
static unsigned char* bdldfp::DecimalConvertUtil::decimalToNetwork ( unsigned char *  buffer,
Decimal128  decimal 
) [static]

Store the specified decimal, in network format, into the specified buffer and return the address one past the last byte written into the buffer. The network format is defined as big endian byte order and densely packed base-10 significand encoding. This corresponds to the way IBM hardware represents these numbers in memory. The behavior is undefined unless buffer points to a memory area at least sizeof(decimal) in size. Note that these functions always return buffer + sizeof(decimal) on the supported 8-bits-byte architectures.

static const unsigned char* bdldfp::DecimalConvertUtil::decimal32FromNetwork ( Decimal32 decimal,
const unsigned char *  buffer 
) [static]
static const unsigned char* bdldfp::DecimalConvertUtil::decimal64FromNetwork ( Decimal64 decimal,
const unsigned char *  buffer 
) [static]
static const unsigned char* bdldfp::DecimalConvertUtil::decimal128FromNetwork ( Decimal128 decimal,
const unsigned char *  buffer 
) [static]
static const unsigned char* bdldfp::DecimalConvertUtil::decimalFromNetwork ( Decimal32 decimal,
const unsigned char *  buffer 
) [static]
static const unsigned char* bdldfp::DecimalConvertUtil::decimalFromNetwork ( Decimal64 decimal,
const unsigned char *  buffer 
) [static]
static const unsigned char* bdldfp::DecimalConvertUtil::decimalFromNetwork ( Decimal128 decimal,
const unsigned char *  buffer 
) [static]

Store into the specified decimal, the value of the same size base-10 floating-point value stored in network format at the specified buffer address and return the address one past the last byte read from buffer. The network format is defined as big endian byte order and densely packed base-10 significand encoding. This corresponds to the way IBM hardware represents these numbers in memory. The behavior is undefined unless buffer points to a memory area at least sizeof(decimal) bytes. Note that these functions always return buffer + sizeof(decimal) on the supported 8-bits-byte architectures.

static bsls::Types::size_type bdldfp::DecimalConvertUtil::decimal64ToMultiWidthEncoding ( unsigned char *  buffer,
bdldfp::Decimal64  decimal 
) [static]

Store the specified decimal, in the multi-width encoding format, into the specified buffer and return the number of bytes used by the encoding. The behavior is undefined unless buffer points to a memory area with enough room to hold the encode value (which has a maximum size of 8 bytes).

static bsls::Types::size_type bdldfp::DecimalConvertUtil::decimal64ToMultiWidthEncodingRaw ( unsigned char *  buffer,
bdldfp::Decimal64  decimal 
) [static]

If the specified decimal can be encoded in 5 or fewer bytes of the multi-width encoding format, then store decimal into the specified buffer in that format, and return the number of bytes written to buffer. Otherwise, return 0. The behavior is undefined unless buffer points to a memory area having at least 5 bytes. Note that this function does not supporting encoding values requiring a full IEEE network encoding, which is supported by the decimal64ToMultiWidthEncoding function.

static Decimal64 bdldfp::DecimalConvertUtil::decimal64FromMultiWidthEncodingRaw ( const unsigned char *  buffer,
bsls::Types::size_type  size 
) [static]

Decode a decimal value in the multi-width encoding format from the specified buffer having the specified size. Return the decoded value. The behavior is undefined unless buffer has at least size bytes, size is a valid encoding size in the multi-width encoding format, and size <= 5. Note that this function does not support decoding values requiring a full IEEE network encoding, which is supported by the decimal64FromMultiWidthEncoding function.

static bool bdldfp::DecimalConvertUtil::isValidMultiWidthSize ( bsls::Types::size_type  size  )  [static]

Return true if the specified size is a valid encoding size in the multi-width encoding format, and false otherwise. Note that valid encoding sizes are 1, 2, 3, 4, 5 and 8 bytes.

static Decimal64 bdldfp::DecimalConvertUtil::decimal64FromMultiWidthEncoding ( const unsigned char *  buffer,
bsls::Types::size_type  size 
) [static]

Decode a decimal value in the multi-width encoding format from the specified buffer having the specified size. Return the decoded value. The behavior is undefined unless buffer has at least size bytes, and size is a valid encoding size in the multi-width encoding format.

static int bdldfp::DecimalConvertUtil::decimal64FromMultiWidthEncodingIfValid ( Decimal64 decimal,
const unsigned char *  buffer,
bsls::Types::size_type  size 
) [static]

Decode a decimal value in the multi-width encoding format from the specified buffer having the specified size and store the result into the specified decimal parameter. Return 0 on success, and non-zero value otherwise. The behavior is undefined unless buffer has at least size bytes. Note that this function returns a non-zero value and leaves decimal unchanged if size is not a valid encoding size of the multi-width encoding format.

static unsigned char* bdldfp::DecimalConvertUtil::decimal64ToVariableWidthEncoding ( unsigned char *  buffer,
bdldfp::Decimal64  decimal 
) [static]

Store the specified decimal, in the variable-width encoding format, into the specified buffer and return the address one past the last byte written into the buffer. The behavior is undefined unless buffer points to a memory area with enough room to hold the encoded value (which has a maximum size of 9 bytes).

static const unsigned char* bdldfp::DecimalConvertUtil::decimal64FromVariableWidthEncoding ( bdldfp::Decimal64 decimal,
const unsigned char *  buffer 
) [static]

Store into the specified decimal, the value of Decimal64 value stored in the variable-width encoding format at the specified buffer address. Return the address one past the last byte read from buffer. The behavior is undefined unless buffer points to a memory area holding a Decimal64 value encoded in the variable-width encoding format.


The documentation for this struct was generated from the following file: