Table of Contents

Class Fixed64Extensions

Namespace
FixedMathSharp
Assembly
FixedMathSharp.dll

Provides extension methods for the Fixed64 type, enabling additional mathematical, conversion, and comparison operations using a fluent syntax.

public static class Fixed64Extensions
Inheritance
Fixed64Extensions
Inherited Members

Methods

Abs(Fixed64)

Returns the absolute value of a Fixed64 number.

public static Fixed64 Abs(this Fixed64 value)

Parameters

value Fixed64

Returns

Fixed64

AbsLessThan(Fixed64, Fixed64)

Checks if the absolute value of x is less than y.

public static bool AbsLessThan(this Fixed64 x, Fixed64 y)

Parameters

x Fixed64

The value to compare.

y Fixed64

The comparison threshold.

Returns

bool

True if |x| < y; otherwise false.

Acos(Fixed64)

Returns the arccosine of the specified number x, calculated using a combination of the atan and sqrt functions.

public static Fixed64 Acos(this Fixed64 f)

Parameters

f Fixed64

Returns

Fixed64

The arccosine of x in radians.

Exceptions

ArgumentOutOfRangeException

Thrown if x is outside the domain [-1, 1].

Asin(Fixed64)

Returns the arc-sine of a fixed-point number x, which is the angle in radians whose sine is x, using a combination of a Taylor series expansion and trigonometric identities.

For values of x near ±1, the identity asin(x) = π/2 - acos(x) is used for stability. For values of x near 0, a Taylor series expansion is used.

public static Fixed64 Asin(this Fixed64 f)

Parameters

f Fixed64

Returns

Fixed64

The arc-sine of x in radians.

Exceptions

ArithmeticException

Thrown if x is outside the domain [-1, 1].

Atan(Fixed64)

Returns the arctangent of the specified number, using a more accurate approximation for larger values. This function has at least 7 decimals of accuracy.

public static Fixed64 Atan(this Fixed64 f)

Parameters

f Fixed64

Returns

Fixed64

Atan2(Fixed64, Fixed64)

Computes the angle whose tangent is the quotient of two specified numbers.

public static Fixed64 Atan2(this Fixed64 a, Fixed64 b)

Parameters

a Fixed64
b Fixed64

Returns

Fixed64

An angle, θ, measured in radians, such that -π ≤ θ ≤ π, and tan(θ) = y / x, taking into account the quadrants of the inputs to determine the sign of the result.

Remarks

Uses a fixed-point arithmetic approximation for the arc tangent function, which is more efficient than using floating-point arithmetic, especially on systems where floating-point operations are expensive.

Ceil(Fixed64)

Returns the smallest integral value that is greater than or equal to the specified number.

public static Fixed64 Ceil(this Fixed64 value)

Parameters

value Fixed64

Returns

Fixed64

CeilToInt(Fixed64)

Rounds up the Fixed64 value to the nearest integer.

public static int CeilToInt(this Fixed64 x)

Parameters

x Fixed64

Returns

int

CeilToLong(Fixed64)

Rounds up the Fixed64 value to the nearest long.

public static long CeilToLong(this Fixed64 x)

Parameters

x Fixed64

Returns

long

Clamp(Fixed64, Fixed64, Fixed64)

Clamps a fixed-point value between the given minimum and maximum values.

public static Fixed64 Clamp(this Fixed64 value, Fixed64 min, Fixed64 max)

Parameters

value Fixed64
min Fixed64
max Fixed64

Returns

Fixed64

Clamp01(Fixed64)

Clamps value between 0 and 1 and returns value.

public static Fixed64 Clamp01(this Fixed64 f1)

Parameters

f1 Fixed64

Returns

Fixed64

ClampOne(Fixed64)

Clamps the value between -1 and 1 inclusive.

public static Fixed64 ClampOne(this Fixed64 f1)

Parameters

f1 Fixed64

The Fixed64 value to clamp.

Returns

Fixed64

Returns a value clamped between -1 and 1.

Cos(Fixed64)

Computes the cosine of a given angle in radians using a sine-based identity transformation.

public static Fixed64 Cos(this Fixed64 f)

Parameters

f Fixed64

Returns

Fixed64

The cosine of the given angle, in fixed-point format.

Remarks

  • Instead of directly approximating cosine, this function derives cos(x) using the identity cos(x) = sin(x + π/2).
  • The underlying sine function uses complementary reduced-range sine and cosine polynomials so quadrant anchors remain continuous.
  • The function automatically normalizes input values to the range [-π, π] for stability.

CubicInterpolate(Fixed64, Fixed64, Fixed64, Fixed64, Fixed64)

Performs cubic interpolation between two points with tangents at those points.

public static Fixed64 CubicInterpolate(this Fixed64 p0, Fixed64 p1, Fixed64 m0, Fixed64 m1, Fixed64 t)

Parameters

p0 Fixed64

The first point.

p1 Fixed64

The second point.

m0 Fixed64

The tangent at p0.

m1 Fixed64

The tangent at p1.

t Fixed64

A value between 0 and 1 that represents the interpolation factor.

Returns

Fixed64

The interpolated value between p0 and p1.

FastAdd(Fixed64, Fixed64)

Adds two fixed-point numbers by adding their raw Q32.32 payloads without saturation.

public static Fixed64 FastAdd(this Fixed64 a, Fixed64 b)

Parameters

a Fixed64
b Fixed64

Returns

Fixed64

Remarks

This is an unchecked hot-path helper. Use it only when the raw sum is known to fit in long or raw wraparound is an intentional part of the algorithm. Use operator +(Fixed64, Fixed64) for the public saturating add contract.

FastDiv(Fixed64, Fixed64)

Divides two fixed-point numbers with an optimized path for known-positive divisors.

public static Fixed64 FastDiv(this Fixed64 a, Fixed64 b)

Parameters

a Fixed64
b Fixed64

Returns

Fixed64

Remarks

This helper preserves the same deterministic rounding, divide-by-zero, and saturation semantics as operator /(Fixed64, Fixed64). The fast path is only used when y is positive; non-positive divisors fall back to the guarded division operator. Prefer the operator unless the divisor positivity invariant is already proven by the caller.

FastMod(Fixed64, Fixed64)

Computes the raw remainder of two fixed-point numbers without special-case guards.

public static Fixed64 FastMod(this Fixed64 a, Fixed64 b)

Parameters

a Fixed64
b Fixed64

Returns

Fixed64

Remarks

This is an unchecked hot-path helper. It delegates directly to the raw long remainder operation, so raw zero divisors and integer edge cases follow runtime integer remainder behavior. Use operator %(Fixed64, Fixed64) for the public guarded remainder contract.

FastMul(Fixed64, Fixed64)

Multiplies two fixed-point numbers using unchecked Q32.32 partial products.

public static Fixed64 FastMul(this Fixed64 a, Fixed64 b)

Parameters

a Fixed64
b Fixed64

Returns

Fixed64

Remarks

This is an unchecked hot-path helper. It skips the full-width overflow/saturation path used by operator *(Fixed64, Fixed64) and truncates discarded fractional bits instead of applying the operator's round-half-to-even behavior. Use it only when inputs are constrained and that precision tradeoff is acceptable. Integral operands take a direct raw multiplication path.

FastSub(Fixed64, Fixed64)

Subtracts two fixed-point numbers by subtracting their raw Q32.32 payloads without saturation.

public static Fixed64 FastSub(this Fixed64 a, Fixed64 b)

Parameters

a Fixed64
b Fixed64

Returns

Fixed64

Remarks

This is an unchecked hot-path helper. Use it only when the raw difference is known to fit in long or raw wraparound is an intentional part of the algorithm. Use operator -(Fixed64, Fixed64) for the public saturating subtract contract.

Floor(Fixed64)

Returns the largest integer less than or equal to the specified number (floor function). Efficiently zeroes out the fractional part.

public static Fixed64 Floor(this Fixed64 value)

Parameters

value Fixed64

Returns

Fixed64

FloorToInt(Fixed64)

Rounds down the Fixed64 value to the nearest integer.

public static int FloorToInt(this Fixed64 x)

Parameters

x Fixed64

Returns

int

FloorToLong(Fixed64)

Rounds down the Fixed64 value to the nearest long.

public static long FloorToLong(this Fixed64 x)

Parameters

x Fixed64

Returns

long

FuzzyComponentEqual(Fixed64, Fixed64, Fixed64)

Helper method to compare individual vector components for approximate equality, allowing a fractional difference. Handles zero components by only using the allowed percentage difference.

public static bool FuzzyComponentEqual(this Fixed64 a, Fixed64 b, Fixed64 percentage)

Parameters

a Fixed64
b Fixed64
percentage Fixed64

Returns

bool

Hypot(Fixed64, Fixed64)

Calculates the hypotenuse of a right triangle given sides a and b using the Pythagorean theorem: sqrt(a^2 + b^2).

public static Fixed64 Hypot(this Fixed64 a, Fixed64 b)

Parameters

a Fixed64

The length of side a.

b Fixed64

The length of side b.

Returns

Fixed64

The length of the hypotenuse.

IsInteger(Fixed64)

Returns true if the number has no decimal part (i.e., if the number is equivalent to an integer) and False otherwise.

public static bool IsInteger(this Fixed64 value)

Parameters

value Fixed64

Returns

bool

Lerp(Fixed64, Fixed64, Fixed64)

Linearly interpolates between two fixed-point values based on a given interpolation factor.

public static Fixed64 Lerp(this Fixed64 a, Fixed64 b, Fixed64 t)

Parameters

a Fixed64
b Fixed64
t Fixed64

A value between 0 and 1 that represents the interpolation factor.

Returns

Fixed64

The interpolated value between from and to.

Remarks

The interpolation is clamped between from and to based on the value of t. If t is less than 0, the result is from. If t is greater than 1, the result is to.

LessThanEpsilon(Fixed64)

Checks if the value is less than epsilon (i.e., effectively zero). Useful for determining if a value is close enough to zero with a given precision.

public static bool LessThanEpsilon(this Fixed64 d)

Parameters

d Fixed64

Returns

bool

Ln(Fixed64)

Returns the natural logarithm of a specified fixed-point number. Provides at least 7 decimals of accuracy.

public static Fixed64 Ln(this Fixed64 f)

Parameters

f Fixed64

Returns

Fixed64

Log2(Fixed64)

Returns the base-2 logarithm of a specified number. Provides at least 9 decimals of accuracy.

public static Fixed64 Log2(this Fixed64 f)

Parameters

f Fixed64

Returns

Fixed64

Remarks

This implementation is based on Clay. S. Turner's fast binary logarithm algorithm (C. S. Turner, "A Fast Binary Logarithm Algorithm", IEEE Signal Processing Mag., pp. 124,140, Sep. 2010.)

MoreThanEpsilon(Fixed64)

Checks if the value is greater than epsilon (positive or negative). Useful for determining if a value is effectively non-zero with a given precision.

public static bool MoreThanEpsilon(this Fixed64 d)

Parameters

d Fixed64

Returns

bool

Pow(Fixed64, Fixed64)

Raises the base number b to the power of exp. Uses logarithms to compute power efficiently for fixed-point values.

public static Fixed64 Pow(this Fixed64 f, Fixed64 exponent)

Parameters

f Fixed64
exponent Fixed64

Returns

Fixed64

Exceptions

DivideByZeroException

The base was Fixed64.Zero, with a negative expFixed64.Onent

ArgumentOutOfRangeException

The base was negative, with a non-Fixed64.Zero expFixed64.Onent

Pow2(Fixed64)

Raises 2 to the power of x. Provides high accuracy for small values of x.

public static Fixed64 Pow2(this Fixed64 f)

Parameters

f Fixed64

Returns

Fixed64

Round(Fixed64, MidpointRounding)

Rounds a fixed-point number to the nearest integral value, based on the specified rounding mode.

public static Fixed64 Round(this Fixed64 value, MidpointRounding mode = MidpointRounding.ToEven)

Parameters

value Fixed64
mode MidpointRounding

Returns

Fixed64

RoundToInt(Fixed64)

Rounds the Fixed64 value to the nearest integer.

public static int RoundToInt(this Fixed64 x)

Parameters

x Fixed64

Returns

int

RoundToLong(Fixed64)

Rounds the Fixed64 value to the nearest long.

public static long RoundToLong(this Fixed64 x)

Parameters

x Fixed64

Returns

long

RoundToPrecision(Fixed64, int, MidpointRounding)

Rounds a fixed-point number to a specific number of decimal places.

public static Fixed64 RoundToPrecision(this Fixed64 value, int places, MidpointRounding mode = MidpointRounding.ToEven)

Parameters

value Fixed64
places int
mode MidpointRounding

Returns

Fixed64

Sign(Fixed64)

Returns a number indicating the sign of a Fix64 number. Returns 1 if the value is positive, 0 if is 0, and -1 if it is negative.

public static int Sign(this Fixed64 value)

Parameters

value Fixed64

Returns

int

Remarks

Optimized for branchless comparison.

Sin(Fixed64)

Computes the sine of a given angle in radians using complementary reduced-range polynomial approximations.

public static Fixed64 Sin(this Fixed64 f)

Parameters

f Fixed64

Returns

Fixed64

The sine of the given angle, in fixed-point format.

Remarks

The input is normalized to [-π, π], reflected into [0, π/2], and evaluated as sine on [0, π/4] or cosine on [0, π/4]. Exact quadrant anchors remain exact without introducing a discontinuity beside them.

SmoothStep(Fixed64, Fixed64, Fixed64)

Performs a smooth step interpolation using a cubic Hermite curve between two values.

public static Fixed64 SmoothStep(this Fixed64 a, Fixed64 b, Fixed64 t)

Parameters

a Fixed64

The starting value.

b Fixed64

The ending value.

t Fixed64

A value between 0 and 1 that represents the interpolation factor.

Returns

Fixed64

The interpolated value between a and b.

Remarks

The interpolation follows a cubic Hermite curve where the function starts at a, accelerates, and then decelerates towards b, ensuring smooth transitions.

Sqrt(Fixed64)

Returns the square root of a specified fixed-point number.

public static Fixed64 Sqrt(this Fixed64 f)

Parameters

f Fixed64

Returns

Fixed64

Squared(Fixed64)

Squares the Fixed64 value.

public static Fixed64 Squared(this Fixed64 value)

Parameters

value Fixed64

The Fixed64 value to square.

Returns

Fixed64

The squared value.

Tan(Fixed64)

Returns the tangent of x.

public static Fixed64 Tan(this Fixed64 f)

Parameters

f Fixed64

Returns

Fixed64

Remarks

This function is not well-tested. It may be wildly inaccurate.

ToDegrees(Fixed64)

Converts the angle in radians to degrees.

public static Fixed64 ToDegrees(this Fixed64 angleInRadians)

Parameters

angleInRadians Fixed64

Returns

Fixed64

ToRadians(Fixed64)

Converts the angle in degrees to radians.

public static Fixed64 ToRadians(this Fixed64 angleInDegrees)

Parameters

angleInDegrees Fixed64

Returns

Fixed64