ae.utils.math

Number stuff

Modules

distribution
module ae.utils.math.distribution

Very basic (and probably buggy) numeric distribution / probability operations. WIP, do not use.

longmul
module ae.utils.math.longmul

Wrapper for long integer multiplication / division opcodes

Members

Aliases

eq
alias eq = binary!"=="

Aliases of D binary operators as functions. Usable in UFCS.

flipBits
alias flipBits = unary!'~'

Like the ~ operator, but without int-promotion.

ge
alias ge = binary!">="
Undocumented in source.
gt
alias gt = binary!">"
Undocumented in source.
le
alias le = binary!"<="
Undocumented in source.
lt
alias lt = binary!"<"
Undocumented in source.
ne
alias ne = binary!"!="
Undocumented in source.

Functions

average
auto average(T args)

Averages args.

between
bool between(T point, T a, T b)

Return true if a <= point <= b.

bitsFor
ubyte bitsFor(T n)

Returns the number of bits needed to store a number up to n (inclusive).

bound
typeof(Ta + Tb + Tc) bound(Ta a, Tb b, Tc c)

Return b bound by a and c (i.e., min(max(a, b), c)).

compare
int compare(T a, T b)

Returns the logical value of sign(b - a) (but does not actually subtract to avoid overflow).

ilog2
ubyte ilog2(T n)

Integer log2.

isPowerOfTwo
bool isPowerOfTwo(T x)

True if x is some power of two, including 1.

itpl
T itpl(T low, T high, U r, U rLow, U rHigh)

Performs linear interpolation. Returns the point between low and high corresponding to the point where r is between rLow and rHigh.

maximize
void maximize(T v, Args args)

Saturate v to be the largest value between itself and args.

minimize
void minimize(T v, Args args)

Saturate v to be the smallest value between itself and args.

nextPowerOfTwo
T nextPowerOfTwo(T x)

Return the next power of two after x, not including it.

op
auto op(T args)

Apply a binary operation consecutively to args.

rangeIntersection
T rangeIntersection(T a0, T a1, T b0, T b1)

Length of intersection of two segments on a line, or 0 if they do not intersect.

roundUpToPowerOfTwo
T roundUpToPowerOfTwo(T x)

Round up x to the next power of two. If x is already a power of two, returns x.

sign
byte sign(T x)

Returns the sign of x, i.e, -1 if x < 0, +1 if x > 0,, or 0 if x == 0.

sort2
void sort2(T x, T y)

If x > y, swaps x and y.

sqr
auto sqr(T x)

Return x*x.

sum
auto sum(T args)

Sums args.

swapBytes
T swapBytes(T b)

Swap the byte order in an integer value.

Templates

TypeForBits
template TypeForBits(uint bits)

Get the smallest built-in unsigned integer type that can store this many bits of data.

binary
template binary(string op)

Wraps a D binary operator into a function.

unary
template unary(char op)

Wraps a D unary operator into a function. Does not do integer promotion.

Meta

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Authors

Vladimir Panteleev <ae@cy.md>