Skip to content

File include/brisk/core/Math.hpp


Fraction class

template <typename T> Fraction

A template structure for representing and manipulating fractions.

This structure allows operations with fractions, including arithmetic operations, normalization, and conversions between fractions and other numeric types. The fraction is represented as a numerator and a denominator, with the denominator being non-negative and the fraction in its reduced form.
Template param T The type used for the numerator and denominator. It must support basic arithmetic operations and the std::abs function.

Fraction<T> function (Fraction::Fraction<T>)

Fraction(T num = 0, T den = 1)
    : numerator(num), denominator(den)

Constructs a Fraction with the given numerator and denominator.

The constructor normalizes the fraction such that the denominator is positive and the fraction is reduced to its simplest form.
Param num The numerator of the fraction. Default is 0.
Param den The denominator of the fraction. Default is 1.

Fraction(float) = delete

Deleted constructor for float types.

This constructor is disabled to prevent the creation of a Fraction with a float type.

Fraction(double) = delete

Deleted constructor for double types.

This constructor is disabled to prevent the creation of a Fraction with a double type.

normalize function (Fraction::normalize)

void normalize()

Normalizes the fraction.

Ensures that the denominator is positive and the fraction is reduced to its simplest form.

abs function (Fraction::abs)

static T abs(T v)

Computes the absolute value of the given value.
Param v The value whose absolute value is to be computed.
Returns The absolute value of the given value.

numerator variable (Fraction::numerator)

T numerator

The numerator of the fraction.

denominator variable (Fraction::denominator)

T denominator

The denominator of the fraction.

Reflection variable (Fraction::Reflection)

constexpr static std::tuple Reflection

Reflection data for the Fraction structure.

operator+ function (Fraction::operator+)

Fraction operator+() const

Unary plus operator.
Returns A copy of the fraction.

operator- function (Fraction::operator-)

Fraction operator-() const

Unary minus operator.
Returns A fraction with the same denominator but negated numerator.

operator bool function (Fraction::operator bool)

explicit operator bool() const

Converts the fraction to a boolean.
Returns true if the numerator is non-zero, false otherwise.

operator double function (Fraction::operator double)

explicit operator double() const

Converts the fraction to a double.
Returns The floating-point representation of the fraction.

operator float function (Fraction::operator float)

explicit operator float() const

Converts the fraction to a float.
Returns The floating-point representation of the fraction.

operator type-parameter-0-0 function (Fraction::operator type-parameter-0-0)

explicit operator T() const

Converts the fraction to the template type T.
Returns The fractional value as type T.

operator+= function (Fraction::operator+=)

Fraction &operator+=(const Fraction &y)

Adds another fraction to this fraction.
Param y The fraction to be added.
Returns A reference to this fraction after addition.

operator-= function (Fraction::operator-=)

Fraction &operator-=(const Fraction &y)

Subtracts another fraction from this fraction.
Param y The fraction to be subtracted.
Returns A reference to this fraction after subtraction.

operator*= function (Fraction::operator*=)

Fraction &operator*=(const Fraction &y)

Multiplies this fraction by another fraction.
Param y The fraction to multiply by.
Returns A reference to this fraction after multiplication.

operator/= function (Fraction::operator/=)

Fraction &operator/=(const Fraction &y)

Divides this fraction by another fraction.
Param y The fraction to divide by.
Returns A reference to this fraction after division.

gcd function (Fraction::gcd)

static T gcd(T a, T b)

Computes the greatest common divisor of two values.
Param a The first value.
Param b The second value.
Returns The greatest common divisor of the two values.

lcm function (Fraction::lcm)

static T lcm(T a, T b)

Computes the least common multiple of two values.
Param a The first value.
Param b The second value.
Returns The least common multiple of the two values.


sqr function

template <typename T> constexpr T sqr(T x) noexcept

Computes the square of a value.
Template param T The type of the value. Must support multiplication.
Param x The value to be squared.
Returns The square of the given value.


deg2rad variable

template <typename T>
constexpr inline T deg2rad = std::numbers::pi_v<T> / T(180)

Converts degrees to radians.
Template param T The numeric type.


rad2deg variable

template <typename T>
constexpr inline T rad2deg = T(180) / std::numbers::pi_v<T>

Converts radians to degrees.
Template param T The numeric type.


mix function

template <typename T> constexpr T mix(float t, T x, T y)

Performs linear interpolation between two values.
Template param T The type of the values.
Param t The interpolation factor, ranging from 0 to 1.
Param x The starting value.
Param y The ending value.
Returns The interpolated value between x and y.


fract function

template <std::floating_point T> constexpr T fract(T x)

Computes the fractional part of a floating-point value.
Template param T A floating-point type.
Param x The value to be processed.
Returns The fractional part of the given value.


Auto-generated from sources, Revision , https://github.com/brisklib/brisk/blob//include/brisk/