Calculate<TResult>

static class

Perform binary and unary arithmetic operations on generic values. TResult specifies what the operation produces. The correct computator is resolved automatically for each type combination.

Binary Operations
TResult Add<TParamA, TParamB>(TParamA a, TParamB b) a + b
TResult Subtract<TParamA, TParamB>(TParamA a, TParamB b) a - b
TResult Multiply<TParamA, TParamB>(TParamA a, TParamB b) a * b
TResult Divide<TParamA, TParamB>(TParamA a, TParamB b) a / b
TResult Modulo<TParamA, TParamB>(TParamA a, TParamB b) a % b
TResult And<TParamA, TParamB>(TParamA a, TParamB b) a & b
TResult Or<TParamA, TParamB>(TParamA a, TParamB b) a | b
TResult Xor<TParamA, TParamB>(TParamA a, TParamB b) a ^ b
Unary Operations
TResult Plus<TParam>(TParam param) +param
TResult Negate<TParam>(TParam param) -param
TResult Invert<TParam>(TParam param) !param
TResult Complement<TParam>(TParam param) ~param
TResult Increment<TParam>(TParam param) ++param
TResult Decrement<TParam>(TParam param) --param
TResult Cast<TParam>(TParam param) (TResult)param
TResult LeftShift<TParam>(TParam param, int shift) param << shift
TResult RightShift<TParam>(TParam param, int shift) param >> shift

Calculate<TResult>.Try

nested static class

Non-throwing versions of all Calculate<TResult> methods. Returns true and sets result on success; returns false and sets result to default when the operation is not supported for the given types.

Binary Operations
bool Add<TParamA, TParamB>(TParamA a, TParamB b, out TResult result) a + b
bool Subtract<TParamA, TParamB>(TParamA a, TParamB b, out TResult result) a - b
bool Multiply<TParamA, TParamB>(TParamA a, TParamB b, out TResult result) a * b
bool Divide<TParamA, TParamB>(TParamA a, TParamB b, out TResult result) a / b
bool Modulo<TParamA, TParamB>(TParamA a, TParamB b, out TResult result) a % b
bool And<TParamA, TParamB>(TParamA a, TParamB b, out TResult result) a & b
bool Or<TParamA, TParamB>(TParamA a, TParamB b, out TResult result) a | b
bool Xor<TParamA, TParamB>(TParamA a, TParamB b, out TResult result) a ^ b
Unary Operations
bool Plus<TParam>(TParam param, out TResult result) +param
bool Negate<TParam>(TParam param, out TResult result) -param
bool Invert<TParam>(TParam param, out TResult result) !param
bool Complement<TParam>(TParam param, out TResult result) ~param
bool Increment<TParam>(TParam param, out TResult result) ++param
bool Decrement<TParam>(TParam param, out TResult result) --param
bool Cast<TParam>(TParam param, out TResult result) (TResult)param
bool LeftShift<TParam>(TParam param, int shift, out TResult result) param << shift
bool RightShift<TParam>(TParam param, int shift, out TResult result) param >> shift

Evaluate

static class

Perform comparisons and boolean evaluations on generic values. The correct computator is resolved automatically for each type combination.

Binary Comparisons
bool Equal<TParamA, TParamB>(TParamA a, TParamB b) a == b
bool NotEqual<TParamA, TParamB>(TParamA a, TParamB b) a != b
bool GreaterThan<TParamA, TParamB>(TParamA a, TParamB b) a > b
bool LessThan<TParamA, TParamB>(TParamA a, TParamB b) a < b
bool GreaterThanOrEqual<TParamA, TParamB>(TParamA a, TParamB b) a >= b
bool LessThanOrEqual<TParamA, TParamB>(TParamA a, TParamB b) a <= b
Unary Evaluations
bool True<TParam>(TParam param) param is true (operator true)
bool False<TParam>(TParam param) param is false (operator false)

Evaluate.Try

nested static class

Non-throwing versions of all Evaluate methods. Returns true and sets result on success; returns false and sets result to default when the operation is not supported for the given types.

Binary Comparisons
bool Equal<TParamA, TParamB>(TParamA a, TParamB b, out bool result) a == b
bool NotEqual<TParamA, TParamB>(TParamA a, TParamB b, out bool result) a != b
bool GreaterThan<TParamA, TParamB>(TParamA a, TParamB b, out bool result) a > b
bool LessThan<TParamA, TParamB>(TParamA a, TParamB b, out bool result) a < b
bool GreaterThanOrEqual<TParamA, TParamB>(TParamA a, TParamB b, out bool result) a >= b
bool LessThanOrEqual<TParamA, TParamB>(TParamA a, TParamB b, out bool result) a <= b
Unary Evaluations
bool True<TParam>(TParam param, out bool result) param is true (operator true)
bool False<TParam>(TParam param, out bool result) param is false (operator false)

Computable<T>

readonly struct

A generic value wrapper that exposes arithmetic operators directly on the value. Operator overloads work between two Computable<T> of the same T only; for cross-type operations (e.g. int + float), use Calculate<TResult> directly.

Public Fields
T value The underlying value this instance holds.
Constructors & Factory Methods
Computable(T value) Wrap value in a Computable<T>.
static Computable<T> From(T value) Factory equivalent of the constructor.
static Computable<T> From<TOther>(TOther value) Cast value to T first, then wrap it.
Instance Methods
TOther To<TOther>() Cast the underlying value to TOther.
bool Equals(object other) True if other is an equal Computable<T> or a bare T value.
int GetHashCode() Hash code of the underlying value.
string ToString() String representation of the underlying value.
Implicit Conversions
implicit operator T(Computable<T> computable) Extracts the underlying value.
implicit operator Computable<T>(T value) Wraps a value in a Computable<T>.
Arithmetic & Bitwise Operators
Both operands are Computable<T>; result is Computable<T>.
operator +a + b
operator -a - b
operator *a * b
operator /a / b
operator %a % b
operator &a & b
operator |a | b
operator ^a ^ b
Unary & Shift Operators
Operand and result are Computable<T>; shift operators also take an int amount.
operator + (unary)+a
operator - (unary)-a
operator !!a
operator ~~a
operator ++++a
operator ----a
operator <<a << n
operator >>a >> n
Comparison & Boolean Operators
Both operands are Computable<T>; result is bool.
operator ==a == b
operator !=a != b
operator >a > b
operator <a < b
operator >=a >= b
operator <=a <= b
operator truea is true (operator true)
operator falsea is false (operator false)

Math<T>

static class

Generic equivalent of UnityEngine.Mathf and System.Math, built on Calculate<T> and Evaluate. Static readonly constants are computed once per closed type (e.g. Math<float>) and cached. Methods that require transcendental math (rounding, trig, powers, logarithms) cast through double via Calculate<double>; all other methods operate purely through generic arithmetic.

Constants
static readonly T Zero default(T) — zero for numeric types.
static readonly T One (T)1
static readonly T PI π (3.14159...)
static readonly T E Euler's number (2.71828...)
static readonly T Deg2Rad π / 180
static readonly T Rad2Deg 180 / π
Basic
T Abs(T value) Absolute value.
T Sign(T value) Returns One, -One, or Zero.
T Min(T a, T b) Smaller of two values.
T Max(T a, T b) Larger of two values.
T Clamp(T value, T min, T max) Clamps value to [min, max].
T Clamp01(T value) Clamps value to [0, 1].
bool Approximately(T a, T b) True if |b - a| is within a relative epsilon of 1e-6.
Interpolation
T Lerp(T a, T b, T t) Linear interpolation, t clamped to [0, 1].
T LerpUnclamped(T a, T b, T t) Linear interpolation without clamping t.
T InverseLerp(T a, T b, T value) (value - a) / (b - a)
T LerpAngle(T a, T b, T t) Lerp between two angles (degrees) via the shortest arc.
T MoveTowards(T current, T target, T maxDelta) Steps current toward target by at most maxDelta.
T MoveTowardsAngle(T current, T target, T maxDelta) Like MoveTowards but for angles (degrees), taking the shortest arc.
T SmoothStep(T from, T to, T t) Hermite smooth-step interpolation: -2t³ + 3t² blend.
Periodic
T Repeat(T t, T length) Wraps t into [0, length) using modulo with sign correction.
T PingPong(T t, T length) Oscillates t back and forth between 0 and length.
T DeltaAngle(T current, T target) Shortest signed difference between two angles (degrees), in (-180, 180].
Rounding
T Floor(T value) Largest integer less than or equal to value.
T Ceiling(T value) Smallest integer greater than or equal to value.
T Ceil(T value) Alias for Ceiling.
T Round(T value) Rounds to the nearest integer (midpoint rounds to even).
T Truncate(T value) Integer part, truncating toward zero.
Powers & Roots
T Sqrt(T value) Square root.
T Cbrt(T value) Cube root (sign-preserving for negative values).
T Pow(T value, T power) value raised to power.
T Exp(T value) e raised to value.
Logarithms
T Log(T value) Natural logarithm.
T Log(T value, T newBase) Logarithm with a specified base.
T Log2(T value) Base-2 logarithm.
T Log10(T value) Base-10 logarithm.
Trigonometry
T Sin(T value) Sine (radians).
T Cos(T value) Cosine (radians).
T Tan(T value) Tangent (radians).
T Asin(T value) Arc sine, result in [-π/2, π/2].
T Acos(T value) Arc cosine, result in [0, π].
T Atan(T value) Arc tangent, result in (-π/2, π/2).
T Atan2(T y, T x) Two-argument arc tangent of y/x, result in (-π, π].
Hyperbolic
T Sinh(T value) Hyperbolic sine.
T Cosh(T value) Hyperbolic cosine.
T Tanh(T value) Hyperbolic tangent.
T Asinh(T value) Inverse hyperbolic sine.
T Acosh(T value) Inverse hyperbolic cosine.
T Atanh(T value) Inverse hyperbolic tangent.

Math<T>.Try

nested static class

Non-throwing versions of all Math<T> methods. Returns true and sets result on success; returns false and sets result to default when the operation is not supported for the given type. Approximately uses out bool result since the underlying method already returns bool.

Basic
bool Abs(T value, out T result)
bool Sign(T value, out T result)
bool Min(T a, T b, out T result)
bool Max(T a, T b, out T result)
bool Clamp(T value, T min, T max, out T result)
bool Clamp01(T value, out T result)
bool Approximately(T a, T b, out bool result)
Interpolation
bool Lerp(T a, T b, T t, out T result)
bool LerpUnclamped(T a, T b, T t, out T result)
bool InverseLerp(T a, T b, T value, out T result)
bool LerpAngle(T a, T b, T t, out T result)
bool MoveTowards(T current, T target, T maxDelta, out T result)
bool MoveTowardsAngle(T current, T target, T maxDelta, out T result)
bool SmoothStep(T from, T to, T t, out T result)
Periodic
bool Repeat(T t, T length, out T result)
bool PingPong(T t, T length, out T result)
bool DeltaAngle(T current, T target, out T result)
Rounding
bool Floor(T value, out T result)
bool Ceiling(T value, out T result)
bool Ceil(T value, out T result)
bool Round(T value, out T result)
bool Truncate(T value, out T result)
Powers & Roots
bool Sqrt(T value, out T result)
bool Cbrt(T value, out T result)
bool Pow(T value, T power, out T result)
bool Exp(T value, out T result)
Logarithms
bool Log(T value, out T result)
bool Log(T value, T newBase, out T result)
bool Log2(T value, out T result)
bool Log10(T value, out T result)
Trigonometry
bool Sin(T value, out T result)
bool Cos(T value, out T result)
bool Tan(T value, out T result)
bool Asin(T value, out T result)
bool Acos(T value, out T result)
bool Atan(T value, out T result)
bool Atan2(T y, T x, out T result)
Hyperbolic
bool Sinh(T value, out T result)
bool Cosh(T value, out T result)
bool Tanh(T value, out T result)
bool Asinh(T value, out T result)
bool Acosh(T value, out T result)
bool Atanh(T value, out T result)

BinaryCalculator<TResult, TParamA, TParamB>

abstract class

Base class for defining a manual binary (two-operand) computator. Derive from this class anywhere in your Assets folder; the package discovers and registers it automatically at startup. Manual computators take priority over source-generated and default computators.

Abstract Methods
TResult Add(TParamA a, TParamB b) a + b
TResult Subtract(TParamA a, TParamB b) a - b
TResult Multiply(TParamA a, TParamB b) a * b
TResult Divide(TParamA a, TParamB b) a / b
TResult Modulo(TParamA a, TParamB b) a % b
TResult And(TParamA a, TParamB b) a & b
TResult Or(TParamA a, TParamB b) a | b
TResult Xor(TParamA a, TParamB b) a ^ b

UnaryCalculator<TResult, TParam>

abstract class

Base class for defining a manual unary (one-operand) computator. Derive from this class anywhere in your Assets folder; the package discovers and registers it automatically at startup. Manual computators take priority over source-generated and default computators.

Abstract Methods
TResult Plus(TParam param) +param
TResult Negate(TParam param) -param
TResult Invert(TParam param) !param
TResult Complement(TParam param) ~param
TResult Increment(TParam param) ++param
TResult Decrement(TParam param) --param
TResult Cast(TParam param) (TResult)param
TResult LeftShift(TParam param, int shift) param << shift
TResult RightShift(TParam param, int shift) param >> shift

BinaryEvaluator<TParamA, TParamB>

abstract class

Base class for defining a manual binary comparison computator. Derive from this class anywhere in your Assets folder; the package discovers and registers it automatically at startup. Manual computators take priority over source-generated and default computators.

Abstract Methods
bool Equal(TParamA a, TParamB b) a == b
bool NotEqual(TParamA a, TParamB b) a != b
bool GreaterThan(TParamA a, TParamB b) a > b
bool LessThan(TParamA a, TParamB b) a < b
bool GreaterThanOrEqual(TParamA a, TParamB b) a >= b
bool LessThanOrEqual(TParamA a, TParamB b) a <= b

UnaryEvaluator<TParam>

abstract class

Base class for defining a manual boolean computator for a single type. Handles operator true and operator false, which control truthiness in boolean contexts (e.g. if (myValue) or myValue && other). Derive from this class anywhere in your Assets folder; the package discovers and registers it automatically at startup.

Abstract Methods
bool True(TParam param) param is true (operator true)
bool False(TParam param) param is false (operator false)

GenerateComputatorsAttribute

Attribute

Assembly-level attribute that instructs the Generic Arithmetic source generator to produce computator classes at compile time. Apply with [assembly: GenerateComputators(...)]. Generated computators are AOT-safe and take priority over the default computator, but are overridden by manual computators.

Requires the Generic Arithmetic source generator DLL to be present in your project.
Constructors
GenerateComputatorsAttribute(Type type) Generates all four computators (BinaryCalculator, BinaryEvaluator, UnaryCalculator, UnaryEvaluator) using type as result, left operand, and right operand.
GenerateComputatorsAttribute(Type result, Type paramA, Type paramB) Generates BinaryCalculator<TResult,TParamA,TParamB> and BinaryEvaluator<TParamA,TParamB> for cross-type operations.
Properties
Type Result The result type for the generated computators.
Type ParamA The left operand type for the generated computators.
Type ParamB The right operand type for the generated computators.