Namespaces

Functions

fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
    .ComptimeInt => comptime_int,
    .Int => |int_info| std.meta.Int(.unsigned, int_info.bits),
    else => @compileError("absCast only accepts integers"),
}

Returns the absolute value of the integer parameter. Converts result type to un…

Returns the absolute value of the integer parameter. Converts result type to unsigned if needed and returns a value of an unsigned integer type. Use absInt if you want to keep your integer type signed.

fn absInt(x: anytype) !@TypeOf(x)

Returns the absolute value of x, where x is a value of a signed integer type. D…

Returns the absolute value of x, where x is a value of a signed integer type. Does not convert and returns a value of a signed integer type. Use absCast if you want to convert the result and get an unsigned type.

fn acos(x: anytype) @TypeOf(x)

No documentation provided.

fn acosh(x: anytype) @TypeOf(x)

No documentation provided.

fn add(comptime T: type, a: T, b: T) error{Overflow}!T

Returns the sum of a and b. Returns an error on overflow.

fn alignCast(comptime alignment: u29, ptr: anytype) AlignCastError!AlignCastResult(alignment, @TypeOf(ptr))

Align cast a pointer but return an error if it’s the wrong alignment

fn approxEqAbs(comptime T: type, x: T, y: T, tolerance: T) bool

Performs an approximate comparison of two floating point values x and y. Re…

Performs an approximate comparison of two floating point values x and y. Returns true if the absolute difference between them is less or equal than the specified tolerance.

The tolerance parameter is the absolute tolerance used when determining if the two numbers are close enough; a good value for this parameter is a small multiple of floatEps(T).

Note that this function is recommended for comparing small numbers around zero; using approxEqRel is suggested otherwise.

NaN values are never considered equal to any value.

fn approxEqRel(comptime T: type, x: T, y: T, tolerance: T) bool

Performs an approximate comparison of two floating point values x and y. Re…

Performs an approximate comparison of two floating point values x and y. Returns true if the absolute difference between them is less or equal than max(|x|, |y|) * tolerance, where tolerance is a positive number greater than zero.

The tolerance parameter is the relative tolerance used when determining if the two numbers are close enough; a good value for this parameter is usually sqrt(floatEps(T)), meaning that the two numbers are considered equal if at least half of the digits are equal.

Note that for comparisons of small numbers around zero this function won’t give meaningful results, use approxEqAbs instead.

NaN values are never considered equal to any value.

fn asin(x: anytype) @TypeOf(x)

No documentation provided.

fn asinh(x: anytype) @TypeOf(x)

No documentation provided.

fn atan(x: anytype) @TypeOf(x)

No documentation provided.

fn atan2(comptime T: type, y: T, x: T) T

No documentation provided.

fn atanh(x: anytype) @TypeOf(x)

No documentation provided.

inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt

Returns a mask of all ones if value is true, and a mask of all zeroes if value …

Returns a mask of all ones if value is true, and a mask of all zeroes if value is false. Compiles to one instruction for register sized integers.

fn break_f80(x: f80) F80

No documentation provided.

fn cast(comptime T: type, x: anytype) ?T

Cast an integer to a different integer type. If the value doesn’t fit, return n…

Cast an integer to a different integer type. If the value doesn’t fit, return null.

fn cbrt(x: anytype) @TypeOf(x)

No documentation provided.

inline fn ceil(value: anytype) @TypeOf(value)

Returns the smallest integral value not less than the given floating point numbe…

Returns the smallest integral value not less than the given floating point number. Uses a dedicated hardware instruction when available. This is the same as calling the builtin @ceil

fn ceilPowerOfTwo(comptime T: type, value: T) error{Overflow}!T

Returns the next power of two (if the value is not already a power of two). Onl…

Returns the next power of two (if the value is not already a power of two). Only unsigned integers can be used. Zero is not an allowed input. If the value doesn’t fit, returns an error.

fn ceilPowerOfTwoAssert(comptime T: type, value: T) T

Returns the next power of two (if the value is not already a power of two). Onl…

Returns the next power of two (if the value is not already a power of two). Only unsigned integers can be used. Zero is not an allowed input. Asserts that the value fits.

fn ceilPowerOfTwoPromote(comptime T: type, value: T) field_call

Returns the next power of two (if the value is not already a power of two). Onl…

Returns the next power of two (if the value is not already a power of two). Only unsigned integers can be used. Zero is not an allowed input. Result is a type with 1 more bit than the input type.

fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper)

Limit val to the inclusive range [lower, upper].

fn compare(a: anytype, op: CompareOperator, b: anytype) bool

This function does the same thing as comparison operators, however the operator…

This function does the same thing as comparison operators, however the operator is a runtime-known enum value. Works on any operands that support comparison operators.

fn comptimeMod(num: anytype, comptime denom: comptime_int) IntFittingRange(0, denom - 1)

Return the mod of num with the smallest integer type

fn copysign(magnitude: anytype, sign: @TypeOf(magnitude)) @TypeOf(magnitude)

No documentation provided.

inline fn cos(value: anytype) @TypeOf(value)

Cosine trigonometric function on a floating point number. Uses a dedicated hard…

Cosine trigonometric function on a floating point number. Uses a dedicated hardware instruction when available. This is the same as calling the builtin @cos

fn cosh(x: anytype) @TypeOf(x)

No documentation provided.

fn degreesToRadians(comptime T: type, angle_in_degrees: T) T

Converts an angle in degrees to radians. T must be a float type.

fn divCeil(comptime T: type, numerator: T, denominator: T) !T

Divide numerator by denominator, rounding toward positive infinity. Returns an …

Divide numerator by denominator, rounding toward positive infinity. Returns an error on overflow or when denominator is zero.

fn divExact(comptime T: type, numerator: T, denominator: T) !T

Divide numerator by denominator. Return an error if quotient is not an integer,…

Divide numerator by denominator. Return an error if quotient is not an integer, denominator is zero, or on overflow.

fn divFloor(comptime T: type, numerator: T, denominator: T) !T

Divide numerator by denominator, rounding toward negative infinity. Returns an …

Divide numerator by denominator, rounding toward negative infinity. Returns an error on overflow or when denominator is zero.

fn divTrunc(comptime T: type, numerator: T, denominator: T) !T

Divide numerator by denominator, rounding toward zero. Returns an error on over…

Divide numerator by denominator, rounding toward zero. Returns an error on overflow or when denominator is zero.

fn doNotOptimizeAway(val: anytype) void

No documentation provided.

inline fn exp(value: anytype) @TypeOf(value)

Base-e exponential function on a floating point number. Uses a dedicated hardwa…

Base-e exponential function on a floating point number. Uses a dedicated hardware instruction when available. This is the same as calling the builtin @exp

inline fn exp2(value: anytype) @TypeOf(value)

Base-2 exponential function on a floating point number. Uses a dedicated hardwa…

Base-2 exponential function on a floating point number. Uses a dedicated hardware instruction when available. This is the same as calling the builtin @exp2

fn expm1(x: anytype) @TypeOf(x)

No documentation provided.

inline fn fabs(value: anytype) @TypeOf(value)

Returns the absolute value of a floating point number. Uses a dedicated hardwar…

Returns the absolute value of a floating point number. Uses a dedicated hardware instruction when available. This is the same as calling the builtin @fabs

inline fn floatEps(comptime T: type) T

No documentation provided.

inline fn floatExponentBits(comptime T: type) comptime_int

No documentation provided.

inline fn floatExponentMax(comptime T: type) comptime_int

No documentation provided.

inline fn floatExponentMin(comptime T: type) comptime_int

No documentation provided.

inline fn floatFractionalBits(comptime T: type) comptime_int

No documentation provided.

inline fn floatMantissaBits(comptime T: type) comptime_int

No documentation provided.

inline fn floatMax(comptime T: type) T

No documentation provided.

inline fn floatMin(comptime T: type) T

No documentation provided.

inline fn floatTrueMin(comptime T: type) T

No documentation provided.

inline fn floor(value: anytype) @TypeOf(value)

Returns the largest integral value not greater than the given floating point num…

Returns the largest integral value not greater than the given floating point number. Uses a dedicated hardware instruction when available. This is the same as calling the builtin @floor

fn floorPowerOfTwo(comptime T: type, value: T) T

Returns the nearest power of two less than or equal to value, or zero if value …

Returns the nearest power of two less than or equal to value, or zero if value is less than or equal to zero.

fn frexp(x: anytype) Frexp(@TypeOf(x))

No documentation provided.

fn gcd(a: anytype, b: anytype) @TypeOf(a, b)

No documentation provided.

fn hypot(comptime T: type, x: T, y: T) T

No documentation provided.

fn ilogb(x: anytype) i32

No documentation provided.

inline fn inf(comptime T: type) T

No documentation provided.

fn isFinite(x: anytype) bool

No documentation provided.

inline fn isInf(x: anytype) bool

No documentation provided.

fn isNan(x: anytype) bool

No documentation provided.

inline fn isNegativeInf(x: anytype) bool

No documentation provided.

fn isNormal(x: anytype) bool

No documentation provided.

inline fn isPositiveInf(x: anytype) bool

No documentation provided.

fn isPowerOfTwo(int: anytype) bool

Asserts int > 0.

fn isSignalNan(x: anytype) bool

No documentation provided.

fn ldexp(x: anytype, n: i32) @TypeOf(x)

No documentation provided.

fn lerp(a: anytype, b: anytype, t: anytype) @TypeOf(a, b, t)

Performs linear interpolation between a and b based on t. t must be in …

Performs linear interpolation between a and b based on t. t must be in range 0.0 to 1.0. Supports floats and vectors of floats.

This does not guarantee returning b if t is 1 due to floating-point errors. This is monotonic.

fn log(comptime T: type, base: T, x: T) T

No documentation provided.

fn log10(x: anytype) @TypeOf(x)

No documentation provided.

fn log10_int(x: anytype) Log2Int(@TypeOf(x))

No documentation provided.

fn log1p(x: anytype) @TypeOf(x)

No documentation provided.

fn log2(x: anytype) @TypeOf(x)

No documentation provided.

fn log2_int(comptime T: type, x: T) Log2Int(T)

Return the log base 2 of integer value x, rounding down to the nearest integer.

fn log2_int_ceil(comptime T: type, x: T) Log2IntCeil(T)

Return the log base 2 of integer value x, rounding up to the nearest integer.

fn lossyCast(comptime T: type, value: anytype) T

Cast a value to a different type. If the value doesn’t fit in, or can’t be perf…

Cast a value to a different type. If the value doesn’t fit in, or can’t be perfectly represented by, the new type, it will be converted to the closest possible representation.

fn make_f80(repr: F80) f80

No documentation provided.

fn maxInt(comptime T: type) comptime_int

Returns the maximum value of integer type T.

fn minInt(comptime T: type) comptime_int

Returns the minimum value of integer type T.

fn mod(comptime T: type, numerator: T, denominator: T) !T

Returns numerator modulo denominator, or an error if denominator is zero or neg…

Returns numerator modulo denominator, or an error if denominator is zero or negative. Negative numerators never result in negative return values.

fn modf(x: anytype) modf_result(@TypeOf(x))

No documentation provided.

fn mul(comptime T: type, a: T, b: T) error{Overflow}!T

Returns the product of a and b. Returns an error on overflow.

fn mulWide(comptime T: type, a: T, b: T) field_call

Multiply a and b. Return type is wide enough to guarantee no overflow.

inline fn nan(comptime T: type) T

No documentation provided.

fn negate(x: anytype) !@TypeOf(x)

No documentation provided.

fn negateCast(x: anytype) !field_call

Returns the negation of the integer parameter. Result is a signed integer.

fn order(a: anytype, b: anytype) Order

Given two numbers, this function returns the order they are with respect to each…

Given two numbers, this function returns the order they are with respect to each other.

fn pow(comptime T: type, x: T, y: T) T

No documentation provided.

fn powi(comptime T: type, x: T, y: T) error{Overflow, Underflow}!T

No documentation provided.

fn radiansToDegrees(comptime T: type, angle_in_radians: T) T

Converts an angle in radians to degrees. T must be a float type.

fn raiseDivByZero() void

No documentation provided.

fn raiseInexact() void

No documentation provided.

fn raiseInvalid() void

No documentation provided.

fn raiseOverflow() void

No documentation provided.

fn raiseUnderflow() void

No documentation provided.

fn rem(comptime T: type, numerator: T, denominator: T) !T

Returns the remainder when numerator is divided by denominator, or an error if …

Returns the remainder when numerator is divided by denominator, or an error if denominator is zero or negative. Negative numerators can give negative results.

fn rotl(comptime T: type, x: T, r: anytype) T

Rotates left. Only unsigned values can be rotated. Negative shift values resul…

Rotates left. Only unsigned values can be rotated. Negative shift values result in shift modulo the bit count.

fn rotr(comptime T: type, x: T, r: anytype) T

Rotates right. Only unsigned values can be rotated. Negative shift values resu…

Rotates right. Only unsigned values can be rotated. Negative shift values result in shift modulo the bit count.

inline fn round(value: anytype) @TypeOf(value)

Rounds the given floating point number to an integer, away from zero. Uses a de…

Rounds the given floating point number to an integer, away from zero. Uses a dedicated hardware instruction when available. This is the same as calling the builtin @round

fn scalbn(x: anytype, n: i32) @TypeOf(x)

No documentation provided.

fn shl(comptime T: type, a: T, shift_amt: anytype) T

Shifts left. Overflowed bits are truncated. A negative shift amount results in …

Shifts left. Overflowed bits are truncated. A negative shift amount results in a right shift.

fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T

Shifts a left by shift_amt. Returns an error on overflow. shift_amt is unsigned…

Shifts a left by shift_amt. Returns an error on overflow. shift_amt is unsigned.

fn shr(comptime T: type, a: T, shift_amt: anytype) T

Shifts right. Overflowed bits are truncated. A negative shift amount results in…

Shifts right. Overflowed bits are truncated. A negative shift amount results in a left shift.

inline fn sign(i: anytype) @TypeOf(i)

Returns -1, 0, or 1. Supports integer and float types and vectors of integer an…

Returns -1, 0, or 1. Supports integer and float types and vectors of integer and float types. Unsigned integer types will always return 0 or 1. Branchless.

fn signbit(x: anytype) bool

No documentation provided.

inline fn sin(value: anytype) @TypeOf(value)

Sine trigonometric function on a floating point number. Uses a dedicated hardwa…

Sine trigonometric function on a floating point number. Uses a dedicated hardware instruction when available. This is the same as calling the builtin @sin

fn sinh(x: anytype) @TypeOf(x)

No documentation provided.

inline fn snan(comptime T: type) T

No documentation provided.

fn sqrt(x: anytype) Sqrt(@TypeOf(x))

No documentation provided.

fn sub(comptime T: type, a: T, b: T) error{Overflow}!T

Returns a - b, or an error on overflow.

inline fn tan(value: anytype) @TypeOf(value)

Tangent trigonometric function on a floating point number. Uses a dedicated har…

Tangent trigonometric function on a floating point number. Uses a dedicated hardware instruction when available. This is the same as calling the builtin @tan

fn tanh(x: anytype) @TypeOf(x)

No documentation provided.

inline fn trunc(value: anytype) @TypeOf(value)

Rounds the given floating point number to an integer, towards zero. Uses a dedi…

Rounds the given floating point number to an integer, towards zero. Uses a dedicated hardware instruction when available. This is the same as calling the builtin @trunc

Values

e
comptime_float

Euler’s number (e)

epsilon
undefined
f128_epsilon
undefined
f128_max
undefined
f128_min
undefined
f128_toint
undefined
f128_true_min
undefined
f16_epsilon
undefined
f16_max
undefined
f16_min
undefined
f16_toint
undefined
f16_true_min
undefined
f32_epsilon
undefined
f32_max
undefined
f32_min
undefined
f32_toint
undefined
f32_true_min
undefined
f64_epsilon
undefined
f64_max
undefined
f64_min
undefined
f64_toint
undefined
f64_true_min
undefined
f80_epsilon
undefined
f80_max
undefined
f80_min
undefined
f80_toint
undefined
f80_true_min
undefined
inf_f128
undefined
inf_f16
undefined
inf_f32
undefined
inf_f64
undefined
inf_f80
undefined
inf_u128
undefined
inf_u16
undefined
inf_u32
undefined
inf_u64
undefined
ln
undefined
ln10
comptime_float

ln(10)

ln2
comptime_float

ln(2)

log10e
comptime_float

log10(e)

log2e
comptime_float

log2(e)

max
undefined
max3
undefined
min
undefined
min3
undefined
modf32_result
undefined
modf64_result
undefined
nan_f128
f128
nan_f16
f16
nan_f32
f32
nan_f64
f64
nan_f80
undefined
nan_u128
u128
nan_u16
u16
nan_u32
u32
nan_u64
type
phi
comptime_float

Phi or Golden ratio constant (Φ) = (1 + sqrt(5))/2

pi
comptime_float

Archimedes’ constant (π)

qnan_f128
f128
qnan_f16
f16
qnan_f32
f32
qnan_f64
f64
qnan_f80
undefined
qnan_u128
u128
qnan_u16
u16
qnan_u32
u32
qnan_u64
u64
sqrt1_2
comptime_float

1/sqrt(2)

sqrt2
comptime_float

sqrt(2)

tau
type

Circle constant (τ)

two_sqrtpi
comptime_float

2/sqrt(π)

Error Sets