nulib.math

Math Functions

Important: When possible compiler level intrinsics will be used, but in some cases this is not possible; in those cases we opt to focus on readability over performance.

As such these math functions may not be the most performant.

Modules

fixed
module nulib.math.fixed

Nulib Fixed Point Math

floating
module nulib.math.floating

Nulib Floating Point Math

intrinsics
module nulib.math.intrinsics

Bindings to compiler-specific intrinsics wrapped in a nicer interface.

Public Imports

nulib.math.intrinsics
public import nulib.math.intrinsics;
Undocumented in source.
nulib.math.floating
public import nulib.math.floating;
Undocumented in source.

Members

Functions

clamp
T clamp(T value, T min_, T max_)

Clamps scalar value into the given range.

copysign
T copysign(T to, T from)

Copies the sign-bit from one value to another.

cubic
T cubic(T p0, T p1, T p2, T p3, float t)

Interpolates between p0 and p3, using a cubic spline with p1 and p2 as control points.

lerp
T lerp(T a, T b, float t)

Linearly interpolates between a and b

max
T max(T lhs, T rhs)

Returns the larger of the 2 given scalar values.

min
T min(T lhs, T rhs)

Returns the smaller of the 2 given scalar values.

mod
auto mod(T value, T delta)

Modulates the given value, preserving sign bit.

quad
T quad(T p0, T p1, T p2, float t)

Quadilaterally interpolates between p0 and p2, with p1 as a control point.

signbit
bool signbit(T x)

Gets whether the value's sign bit is set.

Variables

E
enum real E;

e = 2.718281...

LN10
enum real LN10;

ln 10 = 2.302585...

LN2
enum real LN2;

ln 2 = 0.693147...

LOG10E
enum real LOG10E;

log10e = 0.434294...

LOG2
enum real LOG2;

log102 = 0.301029...

LOG2E
enum real LOG2E;

log2e = 1.442695...

LOG2T
enum real LOG2T;

log210 = 3.321928...

M_1_PI
enum real M_1_PI;

1 / π = 0.318309...

M_2_PI
enum real M_2_PI;

2 / π = 0.636619...

M_2_SQRTPI
enum real M_2_SQRTPI;

2 / √π = 1.128379...

PI
enum real PI;

π = 3.141592...

PI_2
enum real PI_2;

π / 2 = 1.570796...

PI_4
enum real PI_4;

π / 4 = 0.785398...

SQRT1_2
enum real SQRT1_2;

√$(HALF) = 0.707106...

SQRT2
enum real SQRT2;

√2 = 1.414213...

Meta

Authors

Walter Bright, Don Clugston, Luna Nielsen