SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWDecimal< M > Class Template Reference

Exactly represents a decimal fraction. More...

#include <rw/currency/decimal.h>

Inheritance diagram for RWDecimal< M >:
RWDecimalBase RWFixedDecimal< M >

Public Member Functions

 RWDecimal ()
 
 RWDecimal (const char *str)
 
 RWDecimal (const RWDecimal< M > &d)
 
 RWDecimal (const RWDecimalPortable &)
 
 RWDecimal (int i)
 
 RWDecimal (int m, int e)
 
 RWDecimal (long int i)
 
 RWDecimal (long int m, int e)
 
int decimalPlaces () const
 
int isNumber () const
 
 operator RWDecimalPortable () const
 
RWDecimal< M > & operator*= (const RWDecimal< M > &a)
 
RWDecimal< M > operator+ () const
 
RWDecimal< M > & operator+= (const RWDecimal< M > &a)
 
RWDecimal< M > operator- () const
 
RWDecimal< M > & operator-= (const RWDecimal< M > &a)
 
RWDecimal< M > & operator/= (const RWDecimal< M > &a)
 
RWDecimal< M > & operator= (const RWDecimal< M > &a)
 
void restoreFrom (RWFile &)
 
void restoreFrom (RWvistream &)
 
void saveOn (RWFile &) const
 
void saveOn (RWvostream &) const
 
- Public Member Functions inherited from RWDecimalBase
void swap (RWDecimalBase &rhs)
 

Static Public Member Functions

static RWDecimal< M > from (double)
 
static RWDecimal< M > from (long double)
 
static RWDecimal< M > infinityValue ()
 
static int maxDigits ()
 
static RWDecimal< M > maxValue ()
 
static RWDecimal< M > minValue ()
 
static RWDecimal< M > missingValue ()
 
static RWDecimal< M > NaNValue ()
 
static RWDecimal< M > nullValue ()
 
static void setInexactHandler (void(*eh)(const RWDecimalInexactErr< M > &))
 
static void setOverflowHandler (void(*eh)(const RWDecimalOverflowErr< M > &))
 
static RWDecimal< M > SNaNValue ()
 

Static Public Attributes

static const RWDecimal< M > infinity
 
static const RWDecimal< M > missing
 
static const RWDecimal< M > NaN
 
static const RWDecimal< M > null
 
static const RWDecimal< M > SNaN
 

Related Symbols

(Note that these are not member symbols.)

template<class M >
RWDecimal< M > abs (const RWDecimal< M > &d)
 
template<class M >
bool operator!= (const RWDecimal< M > &a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator* (const RWDecimal< M > &a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator* (const RWDecimal< M > &a, double b)
 
template<class M >
RWDecimal< M > operator* (const RWDecimal< M > &a, int b)
 
template<class M >
RWDecimal< M > operator* (const RWDecimal< M > &a, long b)
 
template<class M >
RWDecimal< M > operator* (double a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator* (int a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator* (long a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator+ (const RWDecimal< M > &a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator+ (const RWDecimal< M > &a, int b)
 
template<class M >
RWDecimal< M > operator+ (const RWDecimal< M > &a, long b)
 
template<class M >
RWDecimal< M > operator+ (int a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator+ (long a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator- (const RWDecimal< M > &a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator- (const RWDecimal< M > &a, int b)
 
template<class M >
RWDecimal< M > operator- (const RWDecimal< M > &a, long b)
 
template<class M >
RWDecimal< M > operator- (int a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator- (long a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator/ (const char *a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator/ (const RWDecimal< M > &a, const char *b)
 
template<class M >
RWDecimal< M > operator/ (const RWDecimal< M > &a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator/ (const RWDecimal< M > &a, const RWDecimalPortable &b)
 
template<class M >
RWDecimal< M > operator/ (const RWDecimal< M > &a, double b)
 
template<class M >
RWDecimal< M > operator/ (const RWDecimal< M > &a, int b)
 
template<class M >
RWDecimal< M > operator/ (const RWDecimal< M > &a, long b)
 
template<class M >
RWDecimal< M > operator/ (const RWDecimalPortable &a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator/ (double a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator/ (int a, const RWDecimal< M > &b)
 
template<class M >
RWDecimal< M > operator/ (long a, const RWDecimal< M > &b)
 
template<class M >
bool operator< (const RWDecimal< M > &a, const RWDecimal< M > &b)
 
template<class M >
RWvostreamoperator<< (RWvostream &strm, const RWDecimal< M > &n)
 
template<class M >
bool operator<= (const RWDecimal< M > &a, const RWDecimal< M > &b)
 
template<class M >
bool operator== (const RWDecimal< M > &a, const RWDecimal< M > &b)
 
template<class M >
bool operator> (const RWDecimal< M > &a, const RWDecimal< M > &b)
 
template<class M >
bool operator>= (const RWDecimal< M > &a, const RWDecimal< M > &b)
 
template<class M >
std::istream & operator>> (std::istream &strm, RWDecimal< M > &d)
 
template<class M >
RWDecimal< M > pow (const RWDecimal< M > &d, int e)
 
template<class M >
RWDecimal< M > round (const RWDecimal< M > &d, int digits, RWDecimalBase::RoundingMethod m)
 
template<class M >
long double toDouble (const RWDecimal< M > &d)
 
template<class M >
long int toInt (const RWDecimal< M > &d, RWDecimalBase::RoundingMethod m)
 
template<class M >
RWCString toString (const RWDecimal< M > &d)
 

Additional Inherited Members

- Public Types inherited from RWDecimalBase
enum  Op {
  assign , add , sub , mult ,
  div , powop , pow10op , conversion
}
 
enum  RoundingMethod {
  PLAIN , UP , DOWN , BANKERS ,
  TRUNCATE
}
 
enum  State {
  normal , nullstate , NaNstate , ctorError ,
  missingstate , SNaNstate , infinitystate
}
 

Detailed Description

template<class M>
class RWDecimal< M >

RWDecimal instances are exact representations of decimal fractions. They behave very similarly to the built-in floating point types, float and double. However, because the built-in types use base 2, they cannot store decimal fractions exactly, resulting in rounding errors and a loss of precision. Since the RWDecimal classes use base 10, they can do decimal math exactly.

RWDecimal is templatized. Three short type names are provided: RWDecimal, RWDecimal, and RWDecimal. Each type provides a different amount of precision, as described below in the Limits section. The trade-off is simple: the more precision, the slower the class.

You may also write your own RWDecimal class. Throughout this section, when we refer to the RWDecimal class, you can assume that it applies to any of the three provided classes, or to one you have defined.

Synopsis
#include <rw/currency/decimal.h> // For RWDecimal<T>
#include <rw/currency/mp2int.h> // For RWMP2Int
cout << "one dollar: " << 100 * x << endl;
Exactly represents a decimal fraction.
Definition decimal.h:246
Example
#include <rw/currency/decimal.h>
#include <rw/currency/mp2int.h>
#include <iostream>
int main() {
RWDecimal<RWMP2Int> penny = "0.01";
for (int i = 100; i--;) {
bank += penny; // deposit 100 pennies
}
bank -= 1; // withdraw a buck
std::cout << (bank == 0 ? "broke!" : "whew! still solvent")
<< std::endl;
return 0;
}

Limits

Class RWDecimal provides three static member functions that can be used to define the limits on an RWDecimal object. These functions return the precision, maximum value, and minimum value of a number:

int RWDecimal<T>::maxDigits(); // indicates precision
RWDecimal<T> RWDecimal<T>::maxValue(); // indicates maximum value
RWDecimal<T> RWDecimal<T>::minValue(); // indicates minimum value
static RWDecimal< M > minValue()
Definition decimal.h:565
static RWDecimal< M > maxValue()
Definition decimal.h:559
static int maxDigits()
Definition decimal.h:553
Note
The precision returned by maxDigits() does not usually represent the number of digits in the maximum value of an RWDecimal object. Rather, it indicates the largest number of digits that will always be supported by that object without returning an overflow error. For example, Table 1 indicates that the maximum value for RWDecimal has 19 digits. Notice, however, that larger 19-digit numbers will cause an overflow error because they exceed the maximum value. Therefore, RWDecimal<RWMP2Int>::maxDigits() returns 18, because that is the number of digits that will always be supported without an overflow error.

The following code snippets demonstrate when an overflow condition caused by exceeding a maximum value will occur:

// Set max to maximum value:
// Add 1 to max to generate an overflow error:
// Set min to minimum value:
// Subtract 1 from min to generate an overflow error:
RWDecimal()
Definition decimal.h:336

Table 1 indicates the minimum and maximum values for RWDecimal when T is replaced by one of the provided multi-precision integer types:

Table 1: Max/Min Value and Digits for RWDecimal
Class Minimum value Max Digits
Maximum value
RWDecimal -39614081257132168796771975167 28
39614081257132168796771975167
RWDecimal -9223372036854775807 18
9223372036854775807
RWDecimal -9007199254740991 15
9007199254740991

Non-Numeric Values

As well as representing a decimal fraction, an RWDecimal can also represent one of several non-numeric values. This concept has several uses, including, for example, representing a null entry from a database or indicating a missing value in data, which is to be subjected to a statistical analysis. Currency Module supports five types of non-numeric values: null, missing, NaN (not a number), SNaN (signaling NaN), and infinity. The SNaN value behaves as a NaN value for all operations except toDouble(). The missing, and NaN values propagate while null values do not. This means that arithmetic operations performed using a missing or an NaN result in a missing or an NaN value, whereas arithmetic operations performed with a null operand return either a valid number or an NaN. Operations performed on infinity follow specific rules detailed in RWDecimalBase::State, and may return infinity, NaN, or zero. Details are given below.

The special static constants RWDecimal::missing, RWDecimal::null, RWDecimal::NaN, RWDecimal::SNaN, and RWDecimal::infinity are the prototype missing, null, NaN, SNaN and infinity values. To set up a non-numeric RWDecimal, use these static variables, along with either the copy constructor or assignment operator. To test for a non-numeric value, use these values, along with an equality operator. You can use the member function isNumber() to test if an RWDecimal has a numeric value.

Arithmetic

For the most part, arithmetic between RWDecimal objects is defined very simply: you get back an exact representation of the result of the operation. However, there are several special cases:

  • Loss of precision. If the result cannot be exactly represented as an RWDecimal object because it has too many significant digits, the result is set to an approximation of the true result, and the precisionLoss error handler is called with an RWDecimalInexactErr object.
  • Overflow/underflow: If the magnitude of the result exceeds the range of RWDecimal, then the overflow error handler is called with an RWDecimalOverflowErr object.
  • Operand of missing: If one of the operands is a missing value, then the result of the arithmetic operation is also a missing value.
  • Operand of null: If both operands are null, the result is also null. In addition and subtraction, a null value behaves as if it were zero. In multiplication, a null behaves like a one. Dividing by a null value returns the numerator, thus here a null behaves like one. Using a null as the numerator in a division returns an NaN.
  • Operand of NaN or SNaN: If one or both of the operands is a NaN or SNaN, the result of the arithmetic operation will be NaN.
  • Operand of infinity: Refer to the table defined in RWDecimalBase::State.

Constructor & Destructor Documentation

◆ RWDecimal() [1/8]

template<class M >
RWDecimal< M >::RWDecimal ( )
inline

Constructs an RWDecimal with a value of null.

◆ RWDecimal() [2/8]

template<class M >
RWDecimal< M >::RWDecimal ( const RWDecimal< M > & d)
inline

Copy constructor. Constructs an RWDecimal that is a copy of the argument.

◆ RWDecimal() [3/8]

template<class M >
RWDecimal< M >::RWDecimal ( const RWDecimalPortable & )

Constructs an RWDecimal representation of the argument. This constructor is most often used implicitly to provide type conversion from one RWDecimal type to another using an RWDecimalPortable object as an intermediate representation.

◆ RWDecimal() [4/8]

template<class M >
RWDecimal< M >::RWDecimal ( int i)
inline

Constructs an RWDecimal with value i. The explicit integer constructors prevent initializations from 0 from being ambiguous. Without the int constructor, the compiler would not know whether to convert 0 to a const char* or a long int.

◆ RWDecimal() [5/8]

template<class M >
RWDecimal< M >::RWDecimal ( long int i)
inline

Constructs an RWDecimal with value i. The explicit integer constructors prevent initializations from 0 from being ambiguous. Without the int constructor, the compiler would not know whether to convert 0 to a const char* or a long int.

◆ RWDecimal() [6/8]

template<class M >
RWDecimal< M >::RWDecimal ( int m,
int e )
inline

Constructs an RWDecimal with value m * 10-e, so that e represents the number of digits after the decimal point.

◆ RWDecimal() [7/8]

template<class M >
RWDecimal< M >::RWDecimal ( long int m,
int e )
inline

Constructs an RWDecimal with value m * 10-e, so that e represents the number of digits after the decimal point.

◆ RWDecimal() [8/8]

template<class M >
RWDecimal< M >::RWDecimal ( const char * str)

Constructs an RWDecimal from the null-terminated character string str. Since we write numbers using base 10, and the RWDecimal class stores numbers using base 10, the number constructed is an exact representation of the string. If the string cannot be successfully parsed as a number, the RWDecimal is initialized to null. If the number in the string cannot be exactly represented (for example, it has too many significant digits) then the appropriate error handler (either the inexact or overflow handler) is called. The string may contain embedded commas to separate groups of digits and may have a leading dollar sign. Negatives can be indicated with a negative sign or by using parentheses. A technical description of the exact input grammar allowed is given in the section "Technical Notes" of the Currency Module User's Guide.

Member Function Documentation

◆ decimalPlaces()

template<class M >
int RWDecimal< M >::decimalPlaces ( ) const
inline

Returns the number of digits to the right of the decimal point.

◆ from() [1/2]

template<class M >
static RWDecimal< M > RWDecimal< M >::from ( double )
static

Converts a floating point value to an RWDecimal. Results may be inexact.

◆ from() [2/2]

template<class M >
static RWDecimal< M > RWDecimal< M >::from ( long double )
static

Converts a floating point value to an RWDecimal. Results may be inexact.

◆ infinityValue()

template<class M >
static RWDecimal< M > RWDecimal< M >::infinityValue ( )
static
Deprecated
As of SourcePro 13, use RWDecimal<M>::infinity.

Specifies the non-numeric value infinity. Use this function to test or to set its value on an RWDecimal.

◆ isNumber()

template<class M >
int RWDecimal< M >::isNumber ( ) const
inline

Returns true if self represents a decimal fraction; returns false if self is not a representation of a number; for example, if self is a null or missing value.

◆ maxDigits()

template<class M >
static int RWDecimal< M >::maxDigits ( )
inlinestatic

Returns the maximum number of digits that an RWDecimal of the indicated type is guaranteed to represent without overflow. In most cases, an RWDecimal can represent some numbers of length actualDigits, where actualDigits=maxDigits() + 1. For example, the maxDigits() value for class RWDecimal is 18, even though the number of digits in the maxValue() for the class is 19.

◆ maxValue()

template<class M >
static RWDecimal< M > RWDecimal< M >::maxValue ( )
inlinestatic

Returns the maximum value that can be represented by this class. The maximum value +1 will always generate an overflow error.

◆ minValue()

template<class M >
static RWDecimal< M > RWDecimal< M >::minValue ( )
inlinestatic

Returns the minimum value that can be represented by this class. The minimum value -1 will always generate an overflow error.

◆ missingValue()

template<class M >
static RWDecimal< M > RWDecimal< M >::missingValue ( )
static
Deprecated
As of SourcePro 13, use RWDecimal<M>::missing.

Specifies the non-numeric value missing. Use this function to test or to set its value on an RWDecimal.

◆ NaNValue()

template<class M >
static RWDecimal< M > RWDecimal< M >::NaNValue ( )
static
Deprecated
As of SourcePro 13, use RWDecimal<M>::NaN.

Specifies the non-numeric value NaN. Use this function to test or to set its value on an RWDecimal.

◆ nullValue()

template<class M >
static RWDecimal< M > RWDecimal< M >::nullValue ( )
static
Deprecated
As of SourcePro 13, use RWDecimal<M>::null.

Specifies the non-numeric value null. Use this function to test or to set its value on an RWDecimal.

◆ operator RWDecimalPortable()

template<class M >
RWDecimal< M >::operator RWDecimalPortable ( ) const

Conversion to a portable decimal object. This is most often used implicitly to interface with a facility such as I/O or type conversion.

◆ operator*=()

template<class M >
RWDecimal< M > & RWDecimal< M >::operator*= ( const RWDecimal< M > & a)
inline

Performs the operation between self and the argument, and then stores the results in self. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

◆ operator+()

template<class M >
RWDecimal< M > RWDecimal< M >::operator+ ( ) const
inline

Returns the result of applying the unary operator.

◆ operator+=()

template<class M >
RWDecimal< M > & RWDecimal< M >::operator+= ( const RWDecimal< M > & a)
inline

Performs the operation between self and the argument, and then stores the results in self. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

◆ operator-()

template<class M >
RWDecimal< M > RWDecimal< M >::operator- ( ) const
inline

Returns the result of applying the unary operator.

◆ operator-=()

template<class M >
RWDecimal< M > & RWDecimal< M >::operator-= ( const RWDecimal< M > & a)
inline

Performs the operation between self and the argument, and then stores the results in self. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

◆ operator/=()

template<class M >
RWDecimal< M > & RWDecimal< M >::operator/= ( const RWDecimal< M > & a)
inline

Performs the operation between self and the argument, and then stores the results in self. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

◆ operator=()

template<class M >
RWDecimal< M > & RWDecimal< M >::operator= ( const RWDecimal< M > & a)
inline

Sets the value of self equal to the value of the argument.

◆ restoreFrom() [1/2]

template<class M >
void RWDecimal< M >::restoreFrom ( RWFile & )

Restores value of self from an RWFile. The RWFile class is provided with Rogue Wave's Essential Tools Module class library. This function requires that you link in the Essential Tools Module library.

◆ restoreFrom() [2/2]

template<class M >
void RWDecimal< M >::restoreFrom ( RWvistream & )

Restores value of self from a virtual stream. The virtual stream class is provided with Rogue Wave's Essential Tools Module class library. This function requires that you link in the Essential Tools Module library.

◆ saveOn() [1/2]

template<class M >
void RWDecimal< M >::saveOn ( RWFile & ) const

Stores value of self to an RWFile in binary format. The RWFile class is provided with Rogue Wave's Essential Tools Module class library. This function requires that you link in the Essential Tools Module library.

◆ saveOn() [2/2]

template<class M >
void RWDecimal< M >::saveOn ( RWvostream & ) const

Stores value of self to a virtual stream. The virtual stream class is provided with Rogue Wave's Essential Tools Module class library. This function requires that you link in the Essential Tools Module library.

◆ setInexactHandler()

template<class M >
static void RWDecimal< M >::setInexactHandler ( void(* eh )(const RWDecimalInexactErr< M > &))
inlinestatic

Sets the function that is called when an "inexact" error occurs. This type of error most often indicates the use of an arithmetic operation that will cause loss of precision in the result. defaultInexactHandler, the default error handler, prints an error message, but does not throw an exception.

◆ setOverflowHandler()

template<class M >
static void RWDecimal< M >::setOverflowHandler ( void(* eh )(const RWDecimalOverflowErr< M > &))
inlinestatic

Sets the function that is called when an "overflow" error occurs. This type of error most often indicates the use of an arithmetic operation that will cause a result larger than can be stored. The default error handler, defaultOverflowHandler, simply throws the error object as a C++ exception.

◆ SNaNValue()

template<class M >
static RWDecimal< M > RWDecimal< M >::SNaNValue ( )
static
Deprecated
As of SourcePro 13, use RWDecimal<M>::SNaN.

Specifies the non-numeric value SNaN. Use this function to test or to set its value on an RWDecimal.

Friends And Related Symbol Documentation

◆ abs()

template<class M >
RWDecimal< M > abs ( const RWDecimal< M > & d)
related

Returns the absolute value of d.

◆ operator!=()

template<class M >
bool operator!= ( const RWDecimal< M > & a,
const RWDecimal< M > & b )
related

The not equal operator returns true if the two operands are not exactly the same, and false otherwise.

◆ operator*() [1/7]

template<class M >
RWDecimal< M > operator* ( const RWDecimal< M > & a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator*() [2/7]

template<class M >
RWDecimal< M > operator* ( const RWDecimal< M > & a,
double b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator*() [3/7]

template<class M >
RWDecimal< M > operator* ( const RWDecimal< M > & a,
int b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator*() [4/7]

template<class M >
RWDecimal< M > operator* ( const RWDecimal< M > & a,
long b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator*() [5/7]

template<class M >
RWDecimal< M > operator* ( double a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator*() [6/7]

template<class M >
RWDecimal< M > operator* ( int a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator*() [7/7]

template<class M >
RWDecimal< M > operator* ( long a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator+() [1/5]

template<class M >
RWDecimal< M > operator+ ( const RWDecimal< M > & a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator+() [2/5]

template<class M >
RWDecimal< M > operator+ ( const RWDecimal< M > & a,
int b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator+() [3/5]

template<class M >
RWDecimal< M > operator+ ( const RWDecimal< M > & a,
long b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator+() [4/5]

template<class M >
RWDecimal< M > operator+ ( int a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator+() [5/5]

template<class M >
RWDecimal< M > operator+ ( long a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator-() [1/5]

template<class M >
RWDecimal< M > operator- ( const RWDecimal< M > & a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator-() [2/5]

template<class M >
RWDecimal< M > operator- ( const RWDecimal< M > & a,
int b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator-() [3/5]

template<class M >
RWDecimal< M > operator- ( const RWDecimal< M > & a,
long b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator-() [4/5]

template<class M >
RWDecimal< M > operator- ( int a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator-() [5/5]

template<class M >
RWDecimal< M > operator- ( long a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [1/11]

template<class M >
RWDecimal< M > operator/ ( const char * a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [2/11]

template<class M >
RWDecimal< M > operator/ ( const RWDecimal< M > & a,
const char * b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [3/11]

template<class M >
RWDecimal< M > operator/ ( const RWDecimal< M > & a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [4/11]

template<class M >
RWDecimal< M > operator/ ( const RWDecimal< M > & a,
const RWDecimalPortable & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [5/11]

template<class M >
RWDecimal< M > operator/ ( const RWDecimal< M > & a,
double b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [6/11]

template<class M >
RWDecimal< M > operator/ ( const RWDecimal< M > & a,
int b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [7/11]

template<class M >
RWDecimal< M > operator/ ( const RWDecimal< M > & a,
long b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [8/11]

template<class M >
RWDecimal< M > operator/ ( const RWDecimalPortable & a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [9/11]

template<class M >
RWDecimal< M > operator/ ( double a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [10/11]

template<class M >
RWDecimal< M > operator/ ( int a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator/() [11/11]

template<class M >
RWDecimal< M > operator/ ( long a,
const RWDecimal< M > & b )
related

These arithmetic operators have their conventional meanings. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.

Note
Operations on sentinel values are defined in RWDecimalBase::State.

◆ operator<()

template<class M >
bool operator< ( const RWDecimal< M > & a,
const RWDecimal< M > & b )
related

The relational operators have their conventional meanings. If one (or both) of the operands is null, missing, NaN, or SNaN, then the result of the operator is undefined.

◆ operator<<()

template<class M >
RWvostream & operator<< ( RWvostream & strm,
const RWDecimal< M > & n )
related

Writes an RWDecimal to an output stream. Output is written in the form -xxx.yyy where the xxx and yyy are integers and only the necessary parts are written. For more elaborate formatting, use an RWDecimalFormat object.

◆ operator<=()

template<class M >
bool operator<= ( const RWDecimal< M > & a,
const RWDecimal< M > & b )
related

The relational operators have their conventional meanings. If one (or both) of the operands is null, missing, NaN, or SNaN, then the result of the operator is undefined.

◆ operator==()

template<class M >
bool operator== ( const RWDecimal< M > & a,
const RWDecimal< M > & b )
related

The equality operator returns true if the two operands are exactly the same, and false otherwise.

◆ operator>()

template<class M >
bool operator> ( const RWDecimal< M > & a,
const RWDecimal< M > & b )
related

The relational operators have their conventional meanings. If one (or both) of the operands is null, missing, NaN, or SNaN, then the result of the operator is undefined.

◆ operator>=()

template<class M >
bool operator>= ( const RWDecimal< M > & a,
const RWDecimal< M > & b )
related

The relational operators have their conventional meanings. If one (or both) of the operands is null, missing, NaN, or SNaN, then the result of the operator is undefined.

◆ operator>>()

template<class M >
std::istream & operator>> ( std::istream & strm,
RWDecimal< M > & d )
related

Reads an RWDecimal from an input stream. Since we write numbers using base 10 and the RWDecimal class stores numbers using base 10, the number constructed is an exact representation of the input. The number may contain embedded commas to separate groups of digits and may have a leading dollar sign. Negatives can be indicated with a negative sign or by using parentheses. A technical description of the exact input grammar allowed is given in the section "Technical Notes" of the Currency Module User's Guide.

◆ pow()

template<class M >
RWDecimal< M > pow ( const RWDecimal< M > & d,
int e )
related

Returns d raised to the exponent e. This computation is likely to cause a loss of precision (and a corresponding call to the precision error handler) if e is at all large, and d has any decimal places.

◆ round()

template<class M >
RWDecimal< M > round ( const RWDecimal< M > & d,
int digits,
RWDecimalBase::RoundingMethod m )
related

Returns d rounded to digits decimal places. The method of rounding is controlled by the optional last parameter. These parameters are enumerated in RWDecimalBase, and their effects are shown in the table below. The last three columns indicate the result of rounding three example numbers to one decimal place. Rounding a negative number returns exactly the same result as rounding the corresponding positive number and making the result negative.

Method Description 1.25 1.35 1.251
PLAIN Rounds towards zero on a tie 1.2 1.3 1.2
UP Always rounds away from zero 1.3 1.4 1.3
DOWN Always rounds toward zero 1.2 1.3 1.2
TRUNCATE Same as DOWN 1.2 1.3 1.2
BANKERS On a tie, round so last digit is even 1.2 1.4 1.3

◆ toDouble()

template<class M >
long double toDouble ( const RWDecimal< M > & d)
related

Converts the argument to a double precision value close to its true value. It will correctly convert arguments with the values, NaN, SNaN, or infinity. Arguments with missing or null are converted to zero.

◆ toInt()

template<class M >
long int toInt ( const RWDecimal< M > & d,
RWDecimalBase::RoundingMethod m )
related

Converts the argument to an integer. The method of rounding is controlled by the optional last parameter as described in detail above in the description of the global function round(). Arguments with missing, null, NaN, SNaN, or infinity are converted to zero.

◆ toString()

template<class M >
RWCString toString ( const RWDecimal< M > & d)
related

Converts an RWDecimal to a string. The string produced by this function has the form -xxx.yyy where the xxx and yyy are integers to the left and right of the decimal. Digits only appear if necessary. For more elaborate formatting, use an RWDecimalFormat object.

Member Data Documentation

◆ infinity

template<class M >
const RWDecimal<M> RWDecimal< M >::infinity
static

Specifies the non-numeric value infinity. Use this static instance to test or to set its value on an RWDecimal.

◆ missing

template<class M >
const RWDecimal<M> RWDecimal< M >::missing
static

Specifies the non-numeric value missing. Use this static instance to test or to set its value on an RWDecimal.

◆ NaN

template<class M >
const RWDecimal<M> RWDecimal< M >::NaN
static

Specifies the non-numeric value NaN. Use this static instance to test or to set its value on an RWDecimal.

◆ null

template<class M >
const RWDecimal<M> RWDecimal< M >::null
static

Specifies the non-numeric value null. Use this static instance to test or to set its value on an RWDecimal.

◆ SNaN

template<class M >
const RWDecimal<M> RWDecimal< M >::SNaN
static

Specifies the non-numeric value SNaN. Use this static instance to test or to set its value on an RWDecimal.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.