Normal arithmetic operators.
More...
|
| GncNumeric | operator+ (GncNumeric a, GncNumeric b) |
| GncNumeric | operator+ (GncNumeric a, int64_t b) |
| GncNumeric | operator+ (int64_t a, GncNumeric b) |
| GncNumeric | operator- (GncNumeric a, GncNumeric b) |
| GncNumeric | operator- (GncNumeric a, int64_t b) |
| GncNumeric | operator- (int64_t a, GncNumeric b) |
| GncNumeric | operator* (GncNumeric a, GncNumeric b) |
| GncNumeric | operator* (GncNumeric a, int64_t b) |
| GncNumeric | operator* (int64_t a, GncNumeric b) |
| GncNumeric | operator/ (GncNumeric a, GncNumeric b) |
| GncNumeric | operator/ (GncNumeric a, int64_t b) |
| GncNumeric | operator/ (int64_t a, GncNumeric b) |
Normal arithmetic operators.
The class arithmetic operators are implemented in terms of these operators. They use GncRational operators internally then call the GncNumeric(GncRational&) constructor which will silently round half-down to obtain int64_t members.
These operators can throw std::overflow_error, std::underflow_error, or std::invalid argument as indicated in the class GncNumeric documentation.
- Parameters
-
| a | The right-side operand |
| b | The left-side operand |
- Returns
- A GncNumeric computed from the operation.
◆ operator*() [1/3]
Definition at line 637 of file gnc-numeric.cpp.
638{
639 if (a.num() == 0 || b.
num() == 0)
640 {
642 return retval;
643 }
645 auto rr = ar * br;
647}
The primary numeric class for representing amounts and values.
int64_t num() const noexcept
Accessor for numerator value.
Rational number class using GncInt128 for the numerator and denominator.
◆ operator*() [2/3]
◆ operator*() [3/3]
◆ operator+() [1/3]
Definition at line 619 of file gnc-numeric.cpp.
620{
621 if (a.num() == 0)
622 return b;
624 return a;
626 auto rr = ar + br;
628}
◆ operator+() [2/3]
◆ operator+() [3/3]
◆ operator-() [1/3]
◆ operator-() [2/3]
◆ operator-() [3/3]
◆ operator/() [1/3]
Definition at line 650 of file gnc-numeric.cpp.
651{
652 if (a.num() == 0)
653 {
655 return retval;
656 }
658 throw std::underflow_error("Attempt to divide by zero.");
659
661 auto rr = ar / br;
663}
◆ operator/() [2/3]
◆ operator/() [3/3]