A type for representing a number with a fixed amount of precision. More...
#include <fixed_point.hpp>
Public Types | |
| using | rep = Rep |
| The representation type. | |
Public Member Functions | |
| template<typename T , typename cuda::std::enable_if_t< cuda::std::is_integral_v< T > &&is_supported_representation_type< Rep >()> * = nullptr> | |
| CUDF_HOST_DEVICE | fixed_point (T const &value, scale_type const &scale) |
| Constructor that will perform shifting to store value appropriately (from integral types) More... | |
| CUDF_HOST_DEVICE | fixed_point (scaled_integer< Rep > s) |
| Constructor that will not perform shifting (assumes value already shifted) More... | |
| template<typename T , typename cuda::std::enable_if_t< cuda::std::is_integral_v< T >> * = nullptr> | |
| CUDF_HOST_DEVICE | fixed_point (T const &value) |
"Scale-less" constructor that constructs fixed_point number with a specified value and scale of zero More... | |
| CUDF_HOST_DEVICE | fixed_point () |
Default constructor that constructs fixed_point number with a value and scale of zero. | |
| template<typename U , typename cuda::std::enable_if_t< cuda::std::is_integral_v< U >> * = nullptr> | |
| constexpr CUDF_HOST_DEVICE | operator U () const |
| Explicit conversion operator for casting to integral types. More... | |
| CUDF_HOST_DEVICE | operator scaled_integer< Rep > () const |
Converts the fixed_point number to a scaled_integer More... | |
| CUDF_HOST_DEVICE rep | value () const |
Method that returns the underlying value of the fixed_point number. More... | |
| CUDF_HOST_DEVICE scale_type | scale () const |
Method that returns the scale of the fixed_point number. More... | |
| constexpr CUDF_HOST_DEVICE | operator bool () const |
Explicit conversion operator to bool More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & | operator+= (fixed_point< Rep1, Rad1 > const &rhs) |
| operator += More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & | operator*= (fixed_point< Rep1, Rad1 > const &rhs) |
| operator *= More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & | operator-= (fixed_point< Rep1, Rad1 > const &rhs) |
| operator -= More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & | operator/= (fixed_point< Rep1, Rad1 > const &rhs) |
| operator /= More... | |
| CUDF_HOST_DEVICE fixed_point< Rep, Rad > & | operator++ () |
| operator ++ (post-increment) More... | |
| CUDF_HOST_DEVICE fixed_point< Rep, Rad > | rescaled (scale_type scale) const |
Method for creating a fixed_point number with a new scale More... | |
| operator std::string () const | |
| Returns a string representation of the fixed_point value. | |
Static Public Attributes | |
| static constexpr auto | rad = Rad |
| The base. | |
Friends | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend fixed_point< Rep1, Rad1 > | operator+ (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator + (for adding two fixed_point numbers) More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend fixed_point< Rep1, Rad1 > | operator- (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator - (for subtracting two fixed_point numbers) More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend fixed_point< Rep1, Rad1 > | operator* (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator * (for multiplying two fixed_point numbers) More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend fixed_point< Rep1, Rad1 > | operator/ (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator / (for dividing two fixed_point numbers) More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend fixed_point< Rep1, Rad1 > | operator% (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator % (for computing the modulo operation of two fixed_point numbers) More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend bool | operator== (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator == (for comparing two fixed_point numbers) More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend bool | operator!= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator != (for comparing two fixed_point numbers) More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend bool | operator<= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator <= (for comparing two fixed_point numbers) More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend bool | operator>= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator >= (for comparing two fixed_point numbers) More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend bool | operator< (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator < (for comparing two fixed_point numbers) More... | |
| template<typename Rep1 , Radix Rad1> | |
| CUDF_HOST_DEVICE friend bool | operator> (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs) |
operator > (for comparing two fixed_point numbers) More... | |
A type for representing a number with a fixed amount of precision.
Currently, only binary and decimal fixed_point numbers are supported. Binary operations can only be performed with other fixed_point numbers
| Rep | The representation type (either int32_t or int64_t) |
| Rad | The radix/base (either Radix::BASE_2 or Radix::BASE_10) |
Definition at line 209 of file fixed_point.hpp.
|
inlineexplicit |
Constructor that will perform shifting to store value appropriately (from integral types)
| T | The integral type that you are constructing from |
| value | The value that will be constructed from |
| scale | The exponent that is applied to Rad to perform shifting |
Definition at line 228 of file fixed_point.hpp.
|
inlineexplicit |
Constructor that will not perform shifting (assumes value already shifted)
| s | scaled_integer that contains scale and already shifted value |
Definition at line 240 of file fixed_point.hpp.
|
inline |
"Scale-less" constructor that constructs fixed_point number with a specified value and scale of zero
| T | The value type being constructing from |
| value | The value that will be constructed from |
Definition at line 253 of file fixed_point.hpp.
|
inlineexplicitconstexpr |
Explicit conversion operator to bool
fixed_point value as a boolean (zero is false, nonzero is true) Definition at line 309 of file fixed_point.hpp.
|
inline |
Converts the fixed_point number to a scaled_integer
scaled_integer representation of the fixed_point number Definition at line 285 of file fixed_point.hpp.
|
inlineexplicitconstexpr |
Explicit conversion operator for casting to integral types.
| U | The integral type that is being explicitly converted to |
fixed_point number in base 10 (aka human readable format) Definition at line 271 of file fixed_point.hpp.
|
inline |
operator *=
| Rep1 | Representation type of the operand rhs |
| Rad1 | Radix (base) type of the operand rhs |
| rhs | The number being multiplied to this |
Definition at line 338 of file fixed_point.hpp.
|
inline |
operator ++ (post-increment)
Definition at line 379 of file fixed_point.hpp.
|
inline |
operator +=
| Rep1 | Representation type of the operand rhs |
| Rad1 | Radix (base) type of the operand rhs |
| rhs | The number being added to this |
Definition at line 323 of file fixed_point.hpp.
|
inline |
operator -=
| Rep1 | Representation type of the operand rhs |
| Rad1 | Radix (base) type of the operand rhs |
| rhs | The number being subtracted from this |
Definition at line 353 of file fixed_point.hpp.
|
inline |
operator /=
| Rep1 | Representation type of the operand rhs |
| Rad1 | Radix (base) type of the operand rhs |
| rhs | The number being divided from this |
Definition at line 368 of file fixed_point.hpp.
|
inline |
Method for creating a fixed_point number with a new scale
The fixed_point number returned will have the same value, underlying representation and radix as this, the only thing changed is the scale.
| scale | The scale of the returned fixed_point number |
fixed_point number with a new scale Definition at line 577 of file fixed_point.hpp.
|
inline |
Method that returns the scale of the fixed_point number.
fixed_point number Definition at line 302 of file fixed_point.hpp.
|
inline |
Method that returns the underlying value of the fixed_point number.
fixed_point number Definition at line 295 of file fixed_point.hpp.
|
friend |
operator != (for comparing two fixed_point numbers)
If _scales are equal, _values are compared. If _scales are not equal, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
lhs and rhs are not equal, false if not Definition at line 745 of file fixed_point.hpp.
|
friend |
operator % (for computing the modulo operation of two fixed_point numbers)
If _scales are equal, the modulus is computed directly. If _scales are not equal, the number with larger _scale is shifted to the smaller _scale, and then the modulus is computed.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
fixed_point number Definition at line 790 of file fixed_point.hpp.
|
friend |
operator * (for multiplying two fixed_point numbers)
_scales are added and _values are multiplied.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
fixed_point product Definition at line 706 of file fixed_point.hpp.
|
friend |
operator + (for adding two fixed_point numbers)
If _scales are equal, _values are added. If _scales are not equal, the number with the larger _scale is shifted to the smaller _scale, and then the _values are added.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
fixed_point sum Definition at line 670 of file fixed_point.hpp.
|
friend |
operator - (for subtracting two fixed_point numbers)
If _scales are equal, _values are subtracted. If _scales are not equal, the number with the larger _scale is shifted to the smaller _scale, and then the _values are subtracted.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
fixed_point difference Definition at line 688 of file fixed_point.hpp.
|
friend |
operator / (for dividing two fixed_point numbers)
_scales are subtracted and _values are divided.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
fixed_point quotient Definition at line 721 of file fixed_point.hpp.
|
friend |
operator < (for comparing two fixed_point numbers)
If _scales are equal, _values are compared. If _scales are not equal, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
lhs less than rhs, false if not Definition at line 772 of file fixed_point.hpp.
|
friend |
operator <= (for comparing two fixed_point numbers)
If _scales are equal, _values are compared. If _scales are not equal, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
lhs less than or equal to rhs, false if not Definition at line 754 of file fixed_point.hpp.
|
friend |
operator == (for comparing two fixed_point numbers)
If _scales are equal, _values are compared. If _scales are not equal, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
lhs and rhs are equal, false if not Definition at line 736 of file fixed_point.hpp.
|
friend |
operator > (for comparing two fixed_point numbers)
If _scales are equal, _values are compared. If _scales are not equal, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
lhs greater than rhs, false if not Definition at line 781 of file fixed_point.hpp.
|
friend |
operator >= (for comparing two fixed_point numbers)
If _scales are equal, _values are compared. If _scales are not equal, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.
| Rep1 | Representation type of the operand lhs and rhs |
| Rad1 | Radix (base) type of the operand lhs and rhs |
| lhs | The left hand side operand |
| rhs | The right hand side operand |
lhs greater than or equal to rhs, false if not Definition at line 763 of file fixed_point.hpp.