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 | 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 208 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 227 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 239 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 252 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 308 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 284 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 270 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 337 of file fixed_point.hpp.
|
inline |
operator ++ (post-increment)
Definition at line 378 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 322 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 352 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 367 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 576 of file fixed_point.hpp.
|
inline |
Method that returns the scale of the fixed_point
number.
fixed_point
number Definition at line 301 of file fixed_point.hpp.
|
inline |
Method that returns the underlying value of the fixed_point
number.
fixed_point
number Definition at line 294 of file fixed_point.hpp.
|
friend |
operator != (for comparing two fixed_point
numbers)
If _scale
s are equal, _value
s are compared. If _scale
s are not equal, the number with the larger _scale
is shifted to the smaller _scale
, and then the _value
s 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 744 of file fixed_point.hpp.
|
friend |
operator % (for computing the modulo operation of two fixed_point
numbers)
If _scale
s are equal, the modulus is computed directly. If _scale
s 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 789 of file fixed_point.hpp.
|
friend |
operator * (for multiplying two fixed_point
numbers)
_scale
s are added and _value
s 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 705 of file fixed_point.hpp.
|
friend |
operator + (for adding two fixed_point
numbers)
If _scale
s are equal, _value
s are added. If _scale
s are not equal, the number with the larger _scale
is shifted to the smaller _scale
, and then the _value
s 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 669 of file fixed_point.hpp.
|
friend |
operator - (for subtracting two fixed_point
numbers)
If _scale
s are equal, _value
s are subtracted. If _scale
s are not equal, the number with the larger _scale
is shifted to the smaller _scale
, and then the _value
s 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 687 of file fixed_point.hpp.
|
friend |
operator / (for dividing two fixed_point
numbers)
_scale
s are subtracted and _value
s 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 720 of file fixed_point.hpp.
|
friend |
operator < (for comparing two fixed_point
numbers)
If _scale
s are equal, _value
s are compared. If _scale
s are not equal, the number with the larger _scale
is shifted to the smaller _scale
, and then the _value
s 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 771 of file fixed_point.hpp.
|
friend |
operator <= (for comparing two fixed_point
numbers)
If _scale
s are equal, _value
s are compared. If _scale
s are not equal, the number with the larger _scale
is shifted to the smaller _scale
, and then the _value
s 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 753 of file fixed_point.hpp.
|
friend |
operator == (for comparing two fixed_point
numbers)
If _scale
s are equal, _value
s are compared. If _scale
s are not equal, the number with the larger _scale
is shifted to the smaller _scale
, and then the _value
s 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 735 of file fixed_point.hpp.
|
friend |
operator > (for comparing two fixed_point
numbers)
If _scale
s are equal, _value
s are compared. If _scale
s are not equal, the number with the larger _scale
is shifted to the smaller _scale
, and then the _value
s 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 780 of file fixed_point.hpp.
|
friend |
operator >= (for comparing two fixed_point
numbers)
If _scale
s are equal, _value
s are compared. If _scale
s are not equal, the number with the larger _scale
is shifted to the smaller _scale
, and then the _value
s 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 762 of file fixed_point.hpp.