numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
|
Class of fractions. More...
#include <num_collect/numbers/fraction.h>
Public Types | |
using | integer_type = IntegerType |
Type of integers. | |
Public Member Functions | |
constexpr | fraction () noexcept |
Constructor. (Initialize to zero.) | |
constexpr | fraction (integer_type integer) noexcept |
Constructor. (Convert from an integer.) | |
constexpr | fraction (integer_type numerator, integer_type denominator) |
Constructor. | |
constexpr auto | add (const fraction &right) -> fraction & |
Add a fraction to this fraction. | |
constexpr auto | denominator () const noexcept -> integer_type |
Get the denominator. | |
constexpr auto | divide_by (const fraction &right) -> fraction & |
Divide this fraction by a fraction. | |
constexpr auto | inverse () const -> fraction |
Get the inverse of this fraction. | |
constexpr auto | multiply (const fraction &right) -> fraction & |
Multiply a fraction to this fraction. | |
constexpr auto | numerator () const noexcept -> integer_type |
Get the numerator. | |
constexpr auto | operator!= (const fraction &right) const noexcept -> bool |
Compare this fraction with another fraction. | |
constexpr auto | operator*= (const fraction &right) -> fraction & |
Multiply a fraction to this fraction. | |
constexpr auto | operator+= (const fraction &right) -> fraction & |
Add a fraction to this fraction. | |
constexpr auto | operator-= (const fraction &right) -> fraction & |
Subtract a fraction from this fraction. | |
constexpr auto | operator/= (const fraction &right) -> fraction & |
Divide this fraction by a fraction. | |
constexpr auto | operator== (const fraction &right) const noexcept -> bool |
Compare this fraction with another fraction. | |
constexpr auto | subtract (const fraction &right) -> fraction & |
Subtract a fraction from this fraction. | |
Private Member Functions | |
constexpr void | normalize () |
Normalize this fraction. | |
Static Private Member Functions | |
static constexpr auto | int_abs (integer_type x) noexcept -> integer_type |
Get the absolute value of an integer. | |
Private Attributes | |
integer_type | denominator_ |
Denominator. | |
integer_type | numerator_ |
Numerator. | |
Class of fractions.
IntegerType | Type of integers. |
Definition at line 43 of file fraction.h.
using num_collect::numbers::fraction< IntegerType >::integer_type = IntegerType |
Type of integers.
Definition at line 46 of file fraction.h.
|
inlineconstexpr |
Constructor.
[in] | numerator | Numerator. |
[in] | denominator | Denominator. |
Definition at line 54 of file fraction.h.
|
inlineconstexprnoexcept |
Constructor. (Convert from an integer.)
[in] | integer | Integer. |
Definition at line 66 of file fraction.h.
|
inlineconstexprnoexcept |
Constructor. (Initialize to zero.)
Definition at line 73 of file fraction.h.
|
inlineconstexpr |
Add a fraction to this fraction.
[in] | right | Right-hand-side object. |
Definition at line 110 of file fraction.h.
|
inlinenodiscardconstexprnoexcept |
|
inlineconstexpr |
Divide this fraction by a fraction.
[in] | right | Right-hand-side object. |
Definition at line 208 of file fraction.h.
|
inlinestaticconstexprprivatenoexcept |
Get the absolute value of an integer.
[in] | x | Integer. |
Definition at line 275 of file fraction.h.
|
inlinenodiscardconstexpr |
|
inlineconstexpr |
Multiply a fraction to this fraction.
[in] | right | Right-hand-side object. |
Definition at line 184 of file fraction.h.
|
inlineconstexprprivate |
Normalize this fraction.
Definition at line 250 of file fraction.h.
|
inlinenodiscardconstexprnoexcept |
|
inlineconstexprnoexcept |
Compare this fraction with another fraction.
[in] | right | Right-hand-side object. |
true | This fraction is different from the given fraction. |
false | This fraction is same with the given fraction. |
Definition at line 242 of file fraction.h.
|
inlineconstexpr |
Multiply a fraction to this fraction.
[in] | right | Right-hand-side object. |
Definition at line 173 of file fraction.h.
|
inlineconstexpr |
Add a fraction to this fraction.
[in] | right | Right-hand-side object. |
Definition at line 99 of file fraction.h.
|
inlineconstexpr |
Subtract a fraction from this fraction.
[in] | right | Right-hand-side object. |
Definition at line 136 of file fraction.h.
|
inlineconstexpr |
Divide this fraction by a fraction.
[in] | right | Right-hand-side object. |
Definition at line 197 of file fraction.h.
|
inlineconstexprnoexcept |
Compare this fraction with another fraction.
[in] | right | Right-hand-side object. |
true | This fraction is same with the given fraction. |
false | This fraction is different from the given fraction. |
Definition at line 229 of file fraction.h.
|
inlineconstexpr |
Subtract a fraction from this fraction.
[in] | right | Right-hand-side object. |
Definition at line 147 of file fraction.h.
|
private |
Denominator.
Definition at line 291 of file fraction.h.
|
private |
Numerator.
Definition at line 288 of file fraction.h.