|
units
Use physical dimensions at compile-time or run-time.
|
Model of a fixed-precision rational number. More...
#include <rational.hpp>
Classes | |
| struct | dummy_arg |
Public Types | |
| using | stype = typename int_types< BITS >::SS |
| Signed type for encoding. More... | |
| using | utype = typename int_types< BITS >::US |
| Unsigned type for encoding. More... | |
Public Types inherited from vnix::rat::encoding< NB, DB > | |
| enum | |
| enum | |
| Mask for each of numerator and denominator. More... | |
| using | utype = typename int_types< BITS >::US |
| Unsigned type for encoding. More... | |
| using | stype = typename int_types< BITS >::SS |
| Signed type for encoding. More... | |
| using | uftype = typename int_types< BITS >::UF |
| Unsigned fast type. More... | |
| using | sftype = typename int_types< BITS >::SF |
| Signed fast type. More... | |
Public Member Functions | |
| constexpr | rational (stype n=0, stype d=1) |
| Initialize from numerator and denominator. More... | |
| template<unsigned ONB, unsigned ODB> | |
| constexpr | rational (rational< ONB, ODB > r) |
| Initialize from other rational. More... | |
| constexpr stype | to_int () const |
| Convert to (signed) integer. More... | |
| constexpr bool | to_bool () const |
| Automatically convert to boolean. More... | |
| constexpr float | to_float () const |
| Convert to float. More... | |
| constexpr double | to_double () const |
| Convert to double. More... | |
| template<unsigned ONB, unsigned ODB> | |
| constexpr rational & | operator+= (rational< ONB, ODB > r) |
| Modify this rational number by adding other rational number. More... | |
| template<unsigned ONB, unsigned ODB> | |
| constexpr rational & | operator-= (rational< ONB, ODB > r) |
| Modify this rational number by subtracting other rational number. More... | |
| constexpr rational | reciprocal () const |
| Reciprocal of this rational number. More... | |
| template<unsigned ONB, unsigned ODB> | |
| constexpr rational & | operator*= (rational< ONB, ODB > r) |
| Modify this rational number by multiplying by other rational number. More... | |
| template<unsigned ONB, unsigned ODB> | |
| constexpr rational & | operator/= (rational< ONB, ODB > r) |
| Modify this rational number by dividing by other rational number. More... | |
| template<unsigned ONB, unsigned ODB> | |
| constexpr rational< NB, DB > & | operator+= (rational< ONB, ODB > r) |
| template<unsigned ONB, unsigned ODB> | |
| constexpr rational< NB, DB > & | operator-= (rational< ONB, ODB > r) |
| template<unsigned ONB, unsigned ODB> | |
| constexpr rational< NB, DB > & | operator*= (rational< ONB, ODB > r) |
| template<unsigned ONB, unsigned ODB> | |
| constexpr rational< NB, DB > & | operator/= (rational< ONB, ODB > r) |
Public Member Functions inherited from vnix::rat::encoding< NB, DB > | |
| constexpr | encoding (normalized_pair< NMR_BITS, DNM_BITS > p) |
| Initialize from normalized numerator and denominator. More... | |
| constexpr int_types< NMR_BITS >::SF | n () const |
| Normalized numerator. More... | |
| constexpr int_types< DNM_BITS >::UF | d () const |
| Normalized denominator. More... | |
Static Public Member Functions | |
| static constexpr utype | encode (rational r) |
| Encoding from rational number. More... | |
| static constexpr rational | decode (utype u) |
| Rational number from encoding. More... | |
Private Types | |
| using | P = encoding< NB, DB > |
Private Member Functions | |
| constexpr | rational (utype u, dummy_arg) |
| Construct from encoding. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from vnix::rat::encoding< NB, DB > | |
| constexpr | encoding (utype c) |
| Allow descendant to construct from code-word. More... | |
Protected Attributes inherited from vnix::rat::encoding< NB, DB > | |
| utype | c_ |
| Unsigned word storing encoding. More... | |
Model of a fixed-precision rational number.
Numerator and denominator are encoded in same unsigned integer word. They form a partition of the bits in the word.
| NB | Number of bits for numerator. |
| DB | Number of bits for denominator. |
Definition at line 27 of file rational.hpp.
|
private |
Definition at line 29 of file rational.hpp.
| using vnix::rat::encoding< NMR_BITS, DNM_BITS >::stype = typename int_types<BITS>::SS |
Signed type for encoding.
Definition at line 23 of file encoding.hpp.
| using vnix::rat::encoding< NMR_BITS, DNM_BITS >::utype = typename int_types<BITS>::US |
Unsigned type for encoding.
Definition at line 22 of file encoding.hpp.
|
inlineprivate |
Construct from encoding.
| u | Encoding of rational number. |
Definition at line 38 of file rational.hpp.
|
inline |
Initialize from numerator and denominator.
| n | Numerator (zero by default). |
| d | Denominator (unity by default). |
Definition at line 47 of file rational.hpp.
|
inline |
Initialize from other rational.
| ONB | Number of numerator-bits in other type of rational. |
| ODB | Number of denominator-bits in other type of rational. |
| r | Copy of other rational. |
Definition at line 55 of file rational.hpp.
|
inlinestatic |
Rational number from encoding.
Definition at line 116 of file rational.hpp.
|
inlinestatic |
Encoding from rational number.
Definition at line 113 of file rational.hpp.
| constexpr rational& vnix::rat::rational< NB, DB >::operator*= | ( | rational< ONB, ODB > | r | ) |
Modify this rational number by multiplying by other rational number.
| ONB | Number of numerator -bits in other rational. |
| ODB | Number of denominator-bits in other rational. |
| r | Other rational number. |
| constexpr rational<NB, DB>& vnix::rat::rational< NB, DB >::operator*= | ( | rational< ONB, ODB > | r | ) |
Definition at line 323 of file rational.hpp.
| constexpr rational& vnix::rat::rational< NB, DB >::operator+= | ( | rational< ONB, ODB > | r | ) |
Modify this rational number by adding other rational number.
| ONB | Number of numerator -bits in other rational. |
| ODB | Number of denominator-bits in other rational. |
| r | Other rational number. |
| constexpr rational<NB, DB>& vnix::rat::rational< NB, DB >::operator+= | ( | rational< ONB, ODB > | r | ) |
Definition at line 241 of file rational.hpp.
| constexpr rational& vnix::rat::rational< NB, DB >::operator-= | ( | rational< ONB, ODB > | r | ) |
Modify this rational number by subtracting other rational number.
| ONB | Number of numerator -bits in other rational. |
| ODB | Number of denominator-bits in other rational. |
| r | Other rational number. |
| constexpr rational<NB, DB>& vnix::rat::rational< NB, DB >::operator-= | ( | rational< ONB, ODB > | r | ) |
Definition at line 264 of file rational.hpp.
| constexpr rational& vnix::rat::rational< NB, DB >::operator/= | ( | rational< ONB, ODB > | r | ) |
Modify this rational number by dividing by other rational number.
| ONB | Number of numerator -bits in other rational. |
| ODB | Number of denominator-bits in other rational. |
| r | Other rational number. |
| constexpr rational<NB, DB>& vnix::rat::rational< NB, DB >::operator/= | ( | rational< ONB, ODB > | r | ) |
Definition at line 332 of file rational.hpp.
|
inline |
Reciprocal of this rational number.
Definition at line 90 of file rational.hpp.
|
inline |
Automatically convert to boolean.
Definition at line 65 of file rational.hpp.
|
inline |
Convert to double.
Definition at line 71 of file rational.hpp.
|
inline |
Convert to float.
Definition at line 68 of file rational.hpp.
|
inline |
Convert to (signed) integer.
Definition at line 59 of file rational.hpp.
1.8.11