SourcePro® 2022.1 |
SourcePro® API Reference Guide |
Represents an arbitrary precision decimal fraction, providing maximum portability. More...
#include <rw/tools/decport.h>
Public Member Functions | |
RWDecimalPortable () | |
RWDecimalPortable (const char *input) | |
RWDecimalPortable (long intPart) | |
RWDecimalPortable (const RWDecimalPortable &dp) | |
RWDecimalPortable (RWDecimalPortable &&dp) | |
RWCString | asString () const |
RWCString | asString (const RWLocale &loc) const |
size_t | binaryStoreSize () const |
unsigned | hash () const |
bool | isNumber () const |
operator RWCString () const | |
RWDecimalPortable & | operator= (const RWDecimalPortable &dp) |
RWDecimalPortable & | operator= (RWDecimalPortable &&dp) |
void | restoreFrom (RWvistream &vis) |
void | restoreFrom (RWFile &file) |
void | saveOn (RWvostream &vos) const |
void | saveOn (RWFile &file) const |
void | swap (RWDecimalPortable &rhs) |
void | trimZeros () |
Public Member Functions inherited from RWDecimalBase | |
void | swap (RWDecimalBase &rhs) |
Friends | |
RWDecimalPortable | operator* (const RWDecimalPortable &, const RWDecimalPortable &) |
RWDecimalPortable | operator+ (const RWDecimalPortable &, const RWDecimalPortable &) |
RWDecimalPortable | operator- (const RWDecimalPortable &) |
bool | operator< (const RWDecimalPortable &x, const RWDecimalPortable &y) |
bool | operator== (const RWDecimalPortable &x, const RWDecimalPortable &y) |
RWDecimalPortable | round (const RWDecimalPortable &, RWssize_t, RoundingMethod) |
double | toDouble (const RWDecimalPortable &) |
long double | toLongDouble (const RWDecimalPortable &) |
Related Functions | |
(Note that these are not member functions.) | |
bool | operator!= (const RWDecimalPortable &x, const RWDecimalPortable &y) |
RWDecimalPortable | operator- (const RWDecimalPortable &x, const RWDecimalPortable &y) |
std::ostream & | operator<< (std::ostream &ostrm, const RWDecimalPortable &x) |
bool | operator<= (const RWDecimalPortable &x, const RWDecimalPortable &y) |
bool | operator> (const RWDecimalPortable &x, const RWDecimalPortable &y) |
bool | operator>= (const RWDecimalPortable &x, const RWDecimalPortable &y) |
std::istream & | operator>> (std::istream &strm, RWDecimalPortable &n) |
typedef unspecified_type | RWssize_t |
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 } |
RWDecimalPortable represents an arbitrary precision decimal fraction.
The RWDecimalPortable class is designed to provide maximum portability. However, its portability is gained at the expense of speed and power. For example, RWDecimalPortable does not support all functionality of the other decimal classes in the Currency Module. In most cases we recommend that you use another of the decimal classes from the Currency Module, but in situations in which the portability of a number is paramount, RWDecimalPortable is useful.
When constructing an RWDecimalPortable from a string, the constructor parses the initial characters of the string until the first non-digit, behaving similarly to the C++ Standard Library function std::strtod(). For example, a string "12E3"
creates an RWDecimalPortable value of 12000.
If an RWDecimalPortable is provided an invalid string, either in the constructor or through assignment, it does not throw an exception. Use isNumber() to determine if the object is valid.
Note that:
|
inline |
The default constructor creates a value initialized to zero (0).
RWDecimalPortable::RWDecimalPortable | ( | const char * | input | ) |
Parses the initial portion of input formatted as a decimal number up to the end of the string, or the first non-decimal character, whichever comes first. The parse behavior is locale-dependent (for decimal points, thousands separator, grouping, etc). If no locale is specified, the default locale is used, and parsing behavior will be defined by that locale, creating possibly unexpected results. To ensure predictable and expected behavior, the program should explicitly specify the locale before using this constructor, and input strings should be formatted according the numeric string facets for that locale.
For more information on conversions between strings and numbers, see the section on numbers in the internationalization chapter of the Essential Tools Module User's Guide.
|
inline |
Constructs a value with intPart as the part before the decimal point.
RWDecimalPortable::RWDecimalPortable | ( | const RWDecimalPortable & | dp | ) |
Copy constructor. The constructed instance is a copy of dp.
RWDecimalPortable::RWDecimalPortable | ( | RWDecimalPortable && | dp | ) |
Move constructor. The constructed instance takes ownership of the data owned by dp.
|
inline |
Returns self as an RWCString using the global locale as determined by the static member function RWLocale::global() for numeric formatting. For example, an English locale could return strings such as -23.21, 0.32, or 432.
|
inline |
Returns the number of bytes required to store self using the saveOn() methods.
|
inline |
Returns a value suitable for hashing.
|
inline |
Returns false
if self represents a NaN
, a missing value, infinity or a NULL
; otherwise returns true
.
|
inline |
Returns self as an RWCString. Format is, for example -23.21 or 0.32 or 432.
RWDecimalPortable& RWDecimalPortable::operator= | ( | const RWDecimalPortable & | dp | ) |
Assignment operator. Self is made a copy of dp.
RWDecimalPortable& RWDecimalPortable::operator= | ( | RWDecimalPortable && | dp | ) |
Move assignment. Self takes ownership of the data owned by dp.
void RWDecimalPortable::restoreFrom | ( | RWvistream & | vis | ) |
Reads vis, replacing the contents of self.
void RWDecimalPortable::restoreFrom | ( | RWFile & | file | ) |
Reads file, replacing the contents of self.
void RWDecimalPortable::saveOn | ( | RWvostream & | vos | ) | const |
Writes the contents of self to vos.
void RWDecimalPortable::saveOn | ( | RWFile & | file | ) | const |
Writes the contents of self to file.
|
inline |
Swaps the data owned by self with the data owned by rhs.
|
inline |
Removes leading zeros before self's decimal point and trailing zeros after.
|
related |
Relational operator. Returns true
if x is not equal to y.
|
friend |
Rudimentary multiplication operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.
|
friend |
Rudimentary addition operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.
|
friend |
Rudimentary negation operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.
|
related |
Rudimentary subtraction operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.
|
friend |
Relational operator. Returns true
if x is less than y.
|
related |
Writes an RWDecimalPortable to an output stream.
|
related |
Relational operator. Returns true
if x is less than or equal to y.
|
friend |
Relational operator. Returns true
if x is equal to y.
|
related |
Relational operator. Returns true
if x is greater than y.
|
related |
Relational operator. Returns true
if x is greater than or equal to y.
|
related |
Reads an RWDecimalPortable from an input stream.
|
friend |
Returns an RWDecimalPortable which is the result of rounding self according to the applied specifications.
|
related |
An unspecified signed integer type.
|
friend |
Returns a double which approximates the value of dp.
|
friend |
Returns a long double which approximates the value of dp.
Copyright © 2022 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |