### IBinaryCodedDecimal

  Objects of the IBinaryCodedDecimal class represent numerical quantities accurately, especially in business and commercial applications for financial calculations.

  This class provides functions to obtain information about, compare, and manipulate IBinaryCoded Decimal objects.

### IBinaryCodedDecimal - Member Functions and Data by Group

### Constructors & Destructor

Construct and destruct BCD objects.

IBinaryCodedDecimal

  The IBinaryCodedDecimal object can be constructed in many different ways. If the number of digits and precisions are provided, the constructed object has the provided digit and precision; otherwise default values are assumed according to the type of the value. If a value is provided during construction, the constructed object has the given value with the appropiate digit and precision; otherwise the constructed object will have a value zero. An exception is thrown if the number of digits in the integral part is larger than the supported value (for example, DEC_DIG) or the provided digit and/or precision are out of range. The valid values should satisfy the following:

                  DIGITS        - the given number of digits
                  PRECISIONS  - the given number of precisions

                  0     <      DIGITS            <=     DEC_DIG
                  0     <=     PRECISIONS     <=     DEC_DIG
                                PRECISIONS     <=     DIGITS

  All the macro constants are defined in :xph.idecimal.hpp:exph..

  Overload 1

      public:
      IBinaryCodedDecimal(long double alDouble)

  Constructs the IBinaryCodedDecimal object to have a value alDouble.
  Note: Precision loss could occur during conversion.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 2

      public:
      IBinaryCodedDecimal( unsigned int nDig,
                           unsigned int nPrec,
                           long double alDouble )

  Constructs the IBinaryCodedDecimal object to have a value alDouble with nDig number of digits and nPrec number of precisions.
  Note: Precision loss could occur during conversion.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 3

      public:
      IBinaryCodedDecimal(double aDouble)

  Constructs the IBinaryCodedDecimal object to have a value aDouble.
  Note: Precision loss could occur during conversion.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 4

      public:
      IBinaryCodedDecimal(unsigned long auLong)

  Constructs the IBinaryCodedDecimal object to have a value auLong with DFT_LNG_DIG number of digits and zero number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 5

      public:
      IBinaryCodedDecimal(unsigned int nDig, unsigned int nPrec)

  Constructs the IBinaryCodedDecimal object to have a value zero with nDig number of digits and nPrec number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 6

      public:
      IBinaryCodedDecimal(int anInt)

  Constructs the IBinaryCodedDecimal object to have a value anInt with DFT_INT_DIG number of digits and zero number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 7

      public:
      IBinaryCodedDecimal(unsigned int auInt)

  Constructs the IBinaryCodedDecimal object to have a value auInt with DFT_INT_DIG number of digits and zero number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 8

      public:
      IBinaryCodedDecimal()

  This is a default constructor. The constructed object has a value zero with attributes of DFT_DIG number of digits and DFT_PREC number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 9

      public:
      IBinaryCodedDecimal(const char* val)

  Constructs the IBinaryCodedDecimal object according to the value represented in the provided string. The number of digits and precisions are set accordingly. The leading and trailing zeros are used when setting up the digit and precision attributes, for example, "00123.4560" has 9 digits and 4 precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 10

      public:
      IBinaryCodedDecimal( unsigned int nDig,
                           unsigned int nPrec,
                           long aLong )

  Constructs the IBinaryCodedDecimal object to have a value aLong with nDig number of digits and nPrec number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 11

      public:
      IBinaryCodedDecimal(long aLong)

  Constructs the IBinaryCodedDecimal object to have a value aLong with DFT_LNG_DIG number of digits and zero number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 12

      public:
      IBinaryCodedDecimal( unsigned int nDig,
                           unsigned int nPrec,
                           unsigned long auLong )

  Constructs the IBinaryCodedDecimal object to have a value auLong with nDig number of digits and nPrec number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 13

      public:
      IBinaryCodedDecimal( unsigned int nDig,
                           unsigned int nPrec,
                           int anInt )

  Constructs the IBinaryCodedDecimal object to have a value anInt with nDig number of digits and nPrec number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 14

      public:
      IBinaryCodedDecimal( unsigned int nDig,
                           unsigned int nPrec,
                           unsigned int auInt )

  Constructs the IBinaryCodedDecimal object to have a value auInt with nDig number of digits and nPrec number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 15

      public:
      IBinaryCodedDecimal( unsigned int nDig,
                           unsigned int nPrec,
                           float afloat )

  Constructs the IBinaryCodedDecimal object to have a value afloat with nDig number of digits and nPrec number of precisions.
  Note: Precision loss could occur during conversion.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 16

      public:
      IBinaryCodedDecimal(float afloat)

  Constructs the IBinaryCodedDecimal object to have a value afloat.
  Note: Precision loss could occur during conversion.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 17

      public:
      IBinaryCodedDecimal( unsigned int nDig,
                           unsigned int nPrec,
                           double aDouble )

  Constructs the IBinaryCodedDecimal object to have a value aDouble with nDig number of digits and nPrec number of precisions.
  Note: Precision loss could occur during conversion.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Assignment Operators

These operators allow you to assign various forms of numbers to a IBinaryCodedDecimal object.

operator =
  Assigns a new value to this object

  Overload 1

      public:
      IBinaryCodedDecimal& operator =(unsigned auInt)

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 2

      public:
      IBinaryCodedDecimal& operator =(int anInt)

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 3

      public:
      IBinaryCodedDecimal& operator =(long double alDouble)

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 4

      public:
      IBinaryCodedDecimal&
        operator =( const IBinaryCodedDecimal& bcd )

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 5

      public:
      IBinaryCodedDecimal& operator =(long aLong)

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 6

      public:
      IBinaryCodedDecimal& operator =(const IDecimalUtil& dut)

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 7

      public:
      IBinaryCodedDecimal& operator =(unsigned long auLong)

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 8

      public:
      IBinaryCodedDecimal& operator =(double aDouble)

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 9

      public:
      IBinaryCodedDecimal& operator =(float aFloat)

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Comparison Operators

Use these operators to compare BCD objects for equality and/or relative magnitude.

operator !=

      public:
      int operator !=(const IDecimalUtil& dut) const

  This operator is used to compare two IBinaryCodedDecimal objects. The right IBinaryCodedDecimal object is converted to the utility class, IDecimalUtil first. Returns 1 if the represented values in both object are not the same; otherwise returns 0.
  Note: IBinaryCodedDecimal uses the utility class IDecimalUtil to perform its operations.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator <

      public:
      int operator <(const IDecimalUtil& dut) const

  This operator is used to compare two IBinaryCodedDecimal objects. The right IBinaryCodedDecimal object is converted to the utility class, IDecimalUtil first. Returns 1 if the left operand represents a smaller value than the right operand; otherwise returns 0.
  Note: IBinaryCodedDecimal uses the utility class IDecimalUtil to perform its operations.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator <=

      public:
      int operator <=(const IDecimalUtil& dut) const

  This operator is used to compare two IBinaryCodedDecimal objects. The right IBinaryCodedDecimal object is converted to the utility class, IDecimalUtil first. Returns 1 if the left operand represents a smaller or same value than the right operand; otherwise returns 0.
  Note: IBinaryCodedDecimal uses the utility class IDecimalUtil to perform its operations.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator ==

      public:
      int operator ==(const IDecimalUtil& dut) const

  This operator is used to compare two IBinaryCodedDecimal objects. The right IBinaryCodedDecimal object is converted to the utility class, IDecimalUtil first. Returns 1 if the represented values in both object are the same; otherwise returns 0.
  Note: IBinaryCodedDecimal uses the utility class IDecimalUtil to perform its operations.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator >

      public:
      int operator >(const IDecimalUtil& dut) const

  This operator is used to compare two IBinaryCodedDecimal objects. The right IBinaryCodedDecimal object is converted to the utility class, IDecimalUtil first. Returns 1 if the left operand represents a larger value than the right operand; otherwise returns 0.
  Note: IBinaryCodedDecimal uses the utility class IDecimalUtil to perform its operations.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator >=

      public:
      int operator >=(const IDecimalUtil& dut) const

  This operator is used to compare two IBinaryCodedDecimal objects. The right IBinaryCodedDecimal object is converted to the utility class, IDecimalUtil first. Returns 1 if the left operand represents a larger or same value than the right operand; otherwise returns 0.
  Note: IBinaryCodedDecimal uses a utility class IDecimalUtil to perform its operations.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Manipulations

Use these operators and methods to perform common operations on BCD objects.

operator !

      public:
      int operator !() const

  Returns 1 if the IBinaryCodedDecimal object contains the value zero; otherwise returns 0.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator *=

      public:
      void operator *=(const IDecimalUtil& dut)

  This operator is used to perform compound assignment between two IBinaryCodedDecimal objects. The right IBinaryCodedDecimal object is converted to the utility class, IDecimalUtil first. The left operand is multiplied by the right operand, the result is stored back to the left operand.
  Note: IBinaryCodedDecimal uses the utility class IDecimalUtil to perform its operations.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator +

      public:
      IBinaryCodedDecimal operator +() const

  This is a unary plus operator. The copy of the original object is returned.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator ++

  This is a increment operator.

  Overload 1

      public:
      IBinaryCodedDecimal operator ++()

  This is a prefix increment operator. The value being represented is incremented by 1 and the object with the new value is returned.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 2

      public:
      IBinaryCodedDecimal operator ++(int)

  This is a postfix increment operator. The original object is returned. As a side effect, the value being represented is incremented by 1.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator +=

      public:
      void operator +=(const IDecimalUtil& dut)

  This operator is used to perform compound assignment between two IBinaryCodedDecimal objects. The right IBinaryCodedDecimal object is converted to the utility class, IDecimalUtil first. The right operand is added to the left operand, the result is stored back to the left operand.
  Note: IBinaryCodedDecimal uses the utility class IDecimalUtil to perform its operations.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator -

      public:
      IBinaryCodedDecimal operator -() const

  This is a unary minus operator. The negation of the object is returned.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator --
  This is a decrement operator.

  Overload 1

      public:
      IBinaryCodedDecimal operator --(int)

  This is a postfix decrement operator. The original object is returned. As a side effect, the value being represented is decremented by 1.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 2

      public:
      IBinaryCodedDecimal operator --()

  This is a prefix decrement operator. The value being represented is decremented by 1 and the object with the new value is returned.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator -=

      public:
      void operator -=(const IDecimalUtil& dut)

  This operator is used to perform compound assignment between two IBinaryCodedDecimal objects. The right IBinaryCodedDecimal object is converted to the utility class, IDecimalUtil first. The left operand is subtracted from the right operand, the result is stored back to the left operand.
  Note: IBinaryCodedDecimal uses the utility class IDecimalUtil to perform its operations.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator /=

      public:
      void operator /=(const IDecimalUtil& dut)

  This operator is used to perform compound assignment between two IBinaryCodedDecimal objects. The right IBinaryCodedDecimal object is converted to the utility class, IDecimalUtil first. The left operand is divided by the right operand, the result is stored back to the left operand.
  Note: IBinaryCodedDecimal uses the utility class IDecimalUtil to perform its operations.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Queries

The methods query the object for status information.

cData

      public:
      const char* cData() const

  Returns a pointer that points to the internal buffer which contains the binary coded decimal value in packed decimal format, for example two digits per byte, the last right nibble contains the sign.

  This expression :xph.(digitsOf() >> 1) + 1:exph. identifies the number of bytes to store the binary coded decimal value.
  Note: The buffer is not null terminated.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

digitsOf

      public:
      int digitsOf() const

  Returns the number of digits represented by the binary coded decimal value.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

isNegative

      public:
      const bool isNegative() const

  Returns true if the IBinaryCodeDecimal object represents a negative value; otherwise returns false.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

isPositive

      public:
      const bool isPositive() const

  Returns true if the IBinaryCodeDecimal object represents a positive value; otherwise returns false.
  Note: Zero is considered as a positive value.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

precisionOf

      public:
      int precisionOf() const

  Returns the number of precisions.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Streaming

These operators and methods support binary streaming of BCD objects.

operator <<=

      public:
      void operator <<=(IDataStream& fromWhere)

  The value and attributes are changed by the input data stream, fromWhere.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator >>=

      public:
      void operator >>=(IDataStream& toWhere)

  The information of this object is streamed out to the toWhere data stream.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

readFromStream

      protected:
      void readFromStream(IDataStream& fromWhere)

  Classes that inherit from IBinaryCodedDecimal can call readFromStream() to get information from the data stream fromWhere for the IBinaryCodedDecimal class.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

writeToStream

      protected:
      void writeToStream(IDataStream& toWhere) const

  Classes that inherit from IBinaryCodedDecimal can call writeToStream() to output the information for the IBinaryCodedDecimal class to the data stream toWhere.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Type Conversions

These methods return the BCD value as binary or text.

asDouble

      public:
      double asDouble() const

  Returns the binary coded decimal as a double value.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

asLong

      public:
      long asLong() const

  Returns the binary coded decimal as a long type value. Any numbers after the decimal point are truncated. If the value in the binary coded decimal is too large or too small to be represented as a long type, the returned value is undefined.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

asString

      public:
      IString asString() const

  Returns the binary coded decimal as IString representation.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### IBinaryCodedDecimal - Inherited Member Functions and Data

#### Inherited Public Functions

  - None

#### Inherited Public Data

  - None

#### Inherited Protected Functions

  - None

#### Inherited Protected Data

  - None