Math API
Fast Approximations for float Math Functions

Fast approximations for math functions on limited precision floats. More...

## Modules

Basic Math Functors in the Math API
Basic math functors in the Math API.

## Functions

Float32 mi::math::fast_sqrt (Float32 i)
A fast implementation of sqrt(x) for floats. More...

Float32 mi::math::fast_exp (Float32 x)
A fast implementation of exp for floats. More...

Float32 mi::math::fast_pow2 (Float32 x)
A fast implementation of pow(2,x) for floats. More...

Float32 mi::math::fast_log2 (Float32 i)
A fast implementation of log2(x) for floats. More...

Float32 mi::math::fast_pow (Float32 b, Float32 e)
A fast implementation of pow(x,y) for floats. More...

Float32 mi::math::acos (Float32 s)
Returns the arc cosine of `s` in radians. More...

Float64 mi::math::acos (Float64 s)
Returns the arc cosine of `s` in radians. More...

bool mi::math::all (Uint8 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::all (Uint16 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::all (Uint32 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::all (Uint64 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::all (Sint8 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::all (Sint16 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::all (Sint32 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::all (Sint64 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::all (Float32 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::all (Float64 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::any (Uint8 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::any (Uint16 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::any (Uint32 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::any (Uint64 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::any (Sint8 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::any (Sint16 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::any (Sint32 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::any (Sint64 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::any (Float32 v)
Returns `true` if `v` is not equal to zero. More...

bool mi::math::any (Float64 v)
Returns `true` if `v` is not equal to zero. More...

Float32 mi::math::asin (Float32 s)
Returns the arc sine of `s` in radians. More...

Float64 mi::math::asin (Float64 s)
Returns the arc sine of `s` in radians. More...

Float32 mi::math::atan (Float32 s)
Returns the arc tangent of `s`. More...

Float64 mi::math::atan (Float64 s)
Returns the arc tangent of `s`. More...

Float32 mi::math::atan2 (Float32 s, Float32 t)
Returns the arc tangent of `s` / `t`. More...

Float64 mi::math::atan2 (Float64 s, Float64 t)
Returns the arc tangent of `s` / `t`. More...

Float32 mi::math::ceil (Float32 s)
Returns the smallest integral value that is not less than `s`. More...

Float64 mi::math::ceil (Float64 s)
Returns the smallest integral value that is not less than `s`. More...

Uint8 mi::math::clamp (Uint8 s, Uint8 low, Uint8 high)
Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`. More...

Uint16 mi::math::clamp (Uint16 s, Uint16 low, Uint16 high)
Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`. More...

Uint32 mi::math::clamp (Uint32 s, Uint32 low, Uint32 high)
Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`. More...

Uint64 mi::math::clamp (Uint64 s, Uint64 low, Uint64 high)
Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`. More...

Sint8 mi::math::clamp (Sint8 s, Sint8 low, Sint8 high)
Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`. More...

Sint16 mi::math::clamp (Sint16 s, Sint16 low, Sint16 high)
Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`. More...

Sint32 mi::math::clamp (Sint32 s, Sint32 low, Sint32 high)
Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`. More...

Sint64 mi::math::clamp (Sint64 s, Sint64 low, Sint64 high)
Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`. More...

Float32 mi::math::clamp (Float32 s, Float32 low, Float32 high)
Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`. More...

Float64 mi::math::clamp (Float64 s, Float64 low, Float64 high)
Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`. More...

Float32 mi::math::cos (Float32 a)
Returns the cosine of `a`. The angle `a` is specified in radians. More...

Float64 mi::math::cos (Float64 a)
Returns the cosine of `a`. The angle `a` is specified in radians. More...

Float32 mi::math::degrees (Float32 r)
Converts radians `r` to degrees. More...

Float64 mi::math::degrees (Float64 r)
Converts radians `r` to degrees. More...

Float32 mi::math::exp2 (Float32 s)
Returns the constant `2` to the power of `s` (exponential function). More...

Float64 mi::math::exp2 (Float64 s)
Returns the constant `2` to the power of `s` (exponential function). More...

Float32 mi::math::floor (Float32 s)
Returns the largest integral value that is not greater than `s`. More...

Float64 mi::math::floor (Float64 s)
Returns the largest integral value that is not greater than `s`. More...

Float32 mi::math::fmod (Float32 a, Float32 b)
Returns `a` modulo `b`, in other words, the remainder of a/b. More...

Float64 mi::math::fmod (Float64 a, Float64 b)
Returns `a` modulo `b`, in other words, the remainder of a/b. More...

Float32 mi::math::frac (Float32 s)
Returns the positive fractional part of `s`. More...

Float64 mi::math::frac (Float64 s)
Returns the positive fractional part of `s`. More...

bool mi::math::is_approx_equal (Float32 left, Float32 right, Float32 e)
Compares the two given values for equality within the given epsilon. More...

bool mi::math::is_approx_equal (Float64 left, Float64 right, Float64 e)
Compares the two given values for equality within the given epsilon. More...

Returns the number of leading zeros of `v`, 32-bit version. More...

Returns the number of leading zeros of `v`, 64-bit version. More...

Float32 mi::math::lerp (Float32 s1, Float32 s2, Float32 t)
Returns the linear interpolation between `s1` and `s2`, i.e., it returns `(1-t) * s1 + t * s2`. More...

Float64 mi::math::lerp (Float64 s1, Float64 s2, Float64 t)
Returns the linear interpolation between `s1` and `s2`, i.e., it returns `(1-t) * s1 + t * s2`. More...

Float32 mi::math::log2 (Float32 s)
Returns the base 2 logarithm of `s`. More...

Float64 mi::math::log2 (Float64 s)
Returns the base 2 logarithm of `s`. More...

Sint32 mi::math::log2_int (const Uint32 v)
Returns the integer log2 of `v`. More...

Sint32 mi::math::log2_int (const Uint64 v)
Returns the integer log2 of `v`. More...

Sint32 mi::math::log2_int (const Float32 v)
Returns the integer log2 of `v`. More...

Sint32 mi::math::log2_int (const Float64 v)
Returns the integer log2 of `v`. More...

template<typename Integer>
Sint32 mi::math::log2_int_ceil (const Integer v)
Returns the integer log2 of `v`, i.e., rounded up to the next integer. More...

Float32 mi::math::log10 (Float32 s)
Returns the base 10 logarithm of `s`. More...

Float64 mi::math::log10 (Float64 s)
Returns the base 10 logarithm of `s`. More...

Float32 mi::math::modf (Float32 s, Float32 &i)
Returns the fractional part of `s` and stores the integral part of `s` in `i`. More...

Float64 mi::math::modf (Float64 s, Float64 &i)
Returns the fractional part of `s` and stores the integral part of `s` in `i`. More...

Uint32 mi::math::pow (Uint32 a, Uint32 b)
Returns `a` to the power of `b`. More...

Uint64 mi::math::pow (Uint64 a, Uint64 b)
Returns `a` to the power of `b`. More...

Sint32 mi::math::pow (Sint32 a, Sint32 b)
Returns `a` to the power of `b`. More...

Sint64 mi::math::pow (Sint64 a, Sint64 b)
Returns `a` to the power of `b`. More...

Float32 mi::math::pow (Float32 a, Float32 b)
Returns `a` to the power of `b`. More...

Float64 mi::math::pow (Float64 a, Float64 b)
Returns `a` to the power of `b`. More...

Converts degrees `d` to radians. More...

Converts degrees `d` to radians. More...

Float32 mi::math::round (Float32 s)
Returns `s` rounded to the nearest integer value. More...

Float64 mi::math::round (Float64 s)
Returns `s` rounded to the nearest integer value. More...

Float32 mi::math::rsqrt (Float32 s)
Returns the reciprocal of the square root of `s`. More...

Float64 mi::math::rsqrt (Float64 s)
Returns the reciprocal of the square root of `s`. More...

Float32 mi::math::saturate (Float32 s)
Returns the value `s` clamped to the range [0,1]. More...

Float64 mi::math::saturate (Float64 s)
Returns the value `s` clamped to the range [0,1]. More...

Sint8 mi::math::sign (Sint8 s)
Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`. More...

Sint16 mi::math::sign (Sint16 s)
Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`. More...

Sint32 mi::math::sign (Sint32 s)
Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`. More...

Sint64 mi::math::sign (Sint64 s)
Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`. More...

Float32 mi::math::sign (Float32 s)
Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`. More...

Float64 mi::math::sign (Float64 s)
Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`. More...

bool mi::math::sign_bit (Sint8 s)
Returns `true` if `s<0` and `false` if `s>=` 0. More...

bool mi::math::sign_bit (Sint16 s)
Returns `true` if `s<0` and `false` if `s>=` 0. More...

bool mi::math::sign_bit (Sint32 s)
Returns `true` if `s<0` and `false` if `s>=` 0. More...

bool mi::math::sign_bit (Sint64 s)
Returns `true` if `s<0` and `false` if `s>=` 0. More...

bool mi::math::sign_bit (Float32 s)
Extracts the sign bit of a single-precision floating point number. More...

bool mi::math::sign_bit (Float64 s)
Extracts the sign bit of a double-precision floating point number. More...

bool mi::math::isinfinite (const Float32 x)
Checks a single-precision floating point number for "infinity". More...

bool mi::math::isinfinite (const Float64 x)
Checks a double-precision floating point number for "infinity". More...

Float32 mi::math::sin (Float32 a)
Returns the sine of `a`. The angle `a` is specified in radians. More...

Float64 mi::math::sin (Float64 a)
Returns the sine of `a`. The angle `a` is specified in radians. More...

void mi::math::sincos (Float32 a, Float32 &s, Float32 &c)
Computes the sine `s` and cosine `c` of angle `a` simultaneously. More...

void mi::math::sincos (Float64 a, Float64 &s, Float64 &c)
Computes the sine `s` and cosine `c` of angle `a` simultaneously. More...

Float32 mi::math::smoothstep (Float32 a, Float32 b, Float32 x)
Returns 0 if `x` is less than `a` and 1 if `x` is greater than `b`. More...

Float64 mi::math::smoothstep (Float64 a, Float64 b, Float64 x)
Returns 0 if `x` is less than `a` and 1 if `x` is greater than `b`. More...

Float32 mi::math::sqrt (Float32 s)
Returns the square root of `s`. More...

Float64 mi::math::sqrt (Float64 s)
Returns the square root of `s`. More...

Float32 mi::math::step (Float32 a, Float32 x)
Returns 0 if `x` is less than `a` and 1 otherwise. More...

Float64 mi::math::step (Float64 a, Float64 x)
Returns 0 if `x` is less than `a` and 1 otherwise. More...

Float32 mi::math::tan (Float32 a)
Returns the tangent of `a`. The angle `a` is specified in radians. More...

Float64 mi::math::tan (Float64 a)
Returns the tangent of `a`. The angle `a` is specified in radians. More...

MI_HOST_DEVICE_INLINE void mi::math::to_rgbe (const Float32 color[3], Uint32 &rgbe)
Encodes a color into RGBE representation. More...

MI_HOST_DEVICE_INLINE void mi::math::to_rgbe (const Float32 color[3], Uint8 rgbe[4])
Encodes a color into RGBE representation. More...

MI_HOST_DEVICE_INLINE void mi::math::from_rgbe (const Uint8 rgbe[4], Float32 color[3])
Decodes a color from RGBE representation. More...

MI_HOST_DEVICE_INLINE void mi::math::from_rgbe (const Uint32 rgbe, Float32 color[3])
Decodes a color from RGBE representation. More...

Sint32 mi::math::dot (Sint32 a, Sint32 b)
Returns the inner product (a.k.a. dot or scalar product) of two integers. More...

Float32 mi::math::dot (Float32 a, Float32 b)
Returns the inner product (a.k.a. dot or scalar product) of two scalars. More...

Float64 mi::math::dot (Float64 a, Float64 b)
Returns the inner product (a.k.a. dot or scalar product) of two scalars. More...

template<class V>
V::value_type mi::math::dot (const V &lhs, const V &rhs)
Returns the inner product (a.k.a. dot or scalar product) of two vectors. More...

template<class V>
V::value_type mi::math::square_length (const V &v)
Returns the squared Euclidean norm of the vector `v`. More...

Float32 mi::math::length (Float32 a)
Returns the Euclidean norm of the scalar `a` (its absolute value). More...

Float64 mi::math::length (Float64 a)
Returns the Euclidean norm of the scalar `a` (its absolute value). More...

template<class V>
V::value_type mi::math::length (const V &v)
Returns the Euclidean norm of the vector `v`. More...

template<class V>
V::value_type mi::math::square_euclidean_distance (const V &lhs, const V &rhs)
Returns the squared Euclidean distance from the vector `lhs` to the vector `rhs`. More...

template<class V>
V::value_type mi::math::euclidean_distance (const V &lhs, const V &rhs)
Returns the Euclidean distance from the vector `lhs` to the vector `rhs`. More...

template<class V>
void mi::math::set_bounds (V &v, const V &low, const V &high)
Bounds the value of vector `v` elementwise to the given `low` and `high` vector values. More...

template<class V>
bool mi::math::is_equal (const V &lhs, const V &rhs)
Returns `true` if vector `lhs` is elementwise equal to vector `rhs`, and `false` otherwise. More...

template<class V>
bool mi::math::is_not_equal (const V &lhs, const V &rhs)
Returns `true` if vector `lhs` is elementwise not equal to vector `rhs`, and `false` otherwise. More...

template<class V>
bool mi::math::lexicographically_less (const V &lhs, const V &rhs)
Returns `true` if vector `lhs` is lexicographically less than vector `rhs`, and `false` otherwise. More...

template<class V>
bool mi::math::lexicographically_less_or_equal (const V &lhs, const V &rhs)
Returns `true` if vector `lhs` is lexicographically less than or equal to vector `rhs`, and `false` otherwise. More...

template<class V>
bool mi::math::lexicographically_greater (const V &lhs, const V &rhs)
Returns `true` if vector `lhs` is lexicographically greater than vector `rhs`, and `false` otherwise. More...

template<class V>
bool mi::math::lexicographically_greater_or_equal (const V &lhs, const V &rhs)
Returns `true` if vector `lhs` is lexicographically greater than or equal to vector `rhs`, and `false` otherwise. More...

template<class V>
Comparison_result mi::math::lexicographically_compare (const V &lhs, const V &rhs)
Compares two vectors lexicographically. More...

## Detailed Description

Fast approximations for math functions on limited precision floats.

Include File:
` #include <mi/math/function.h>`

## ◆ acos() [1/2]

 Float32 mi::math::acos ( Float32 s )
inline

Returns the arc cosine of `s` in radians.

## ◆ acos() [2/2]

 Float64 mi::math::acos ( Float64 s )
inline

Returns the arc cosine of `s` in radians.

## ◆ all() [1/10]

 bool mi::math::all ( Float32 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ all() [2/10]

 bool mi::math::all ( Float64 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ all() [3/10]

 bool mi::math::all ( Sint16 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ all() [4/10]

 bool mi::math::all ( Sint32 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ all() [5/10]

 bool mi::math::all ( Sint64 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ all() [6/10]

 bool mi::math::all ( Sint8 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ all() [7/10]

 bool mi::math::all ( Uint16 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ all() [8/10]

 bool mi::math::all ( Uint32 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ all() [9/10]

 bool mi::math::all ( Uint64 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ all() [10/10]

 bool mi::math::all ( Uint8 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ any() [1/10]

 bool mi::math::any ( Float32 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ any() [2/10]

 bool mi::math::any ( Float64 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ any() [3/10]

 bool mi::math::any ( Sint16 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ any() [4/10]

 bool mi::math::any ( Sint32 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ any() [5/10]

 bool mi::math::any ( Sint64 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ any() [6/10]

 bool mi::math::any ( Sint8 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ any() [7/10]

 bool mi::math::any ( Uint16 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ any() [8/10]

 bool mi::math::any ( Uint32 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ any() [9/10]

 bool mi::math::any ( Uint64 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ any() [10/10]

 bool mi::math::any ( Uint8 v )
inline

Returns `true` if `v` is not equal to zero.

## ◆ asin() [1/2]

 Float32 mi::math::asin ( Float32 s )
inline

Returns the arc sine of `s` in radians.

## ◆ asin() [2/2]

 Float64 mi::math::asin ( Float64 s )
inline

Returns the arc sine of `s` in radians.

## ◆ atan() [1/2]

 Float32 mi::math::atan ( Float32 s )
inline

Returns the arc tangent of `s`.

## ◆ atan() [2/2]

 Float64 mi::math::atan ( Float64 s )
inline

Returns the arc tangent of `s`.

## ◆ atan2() [1/2]

 Float32 mi::math::atan2 ( Float32 s, Float32 t )
inline

Returns the arc tangent of `s` / `t`.

The signs of `s` and `t` are used to determine the quadrant of the results.

## ◆ atan2() [2/2]

 Float64 mi::math::atan2 ( Float64 s, Float64 t )
inline

Returns the arc tangent of `s` / `t`.

The signs of `s` and `t` are used to determine the quadrant of the results.

## ◆ ceil() [1/2]

 Float32 mi::math::ceil ( Float32 s )
inline

Returns the smallest integral value that is not less than `s`.

## ◆ ceil() [2/2]

 Float64 mi::math::ceil ( Float64 s )
inline

Returns the smallest integral value that is not less than `s`.

## ◆ clamp() [1/10]

 Float32 mi::math::clamp ( Float32 s, Float32 low, Float32 high )
inline

Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`.

## ◆ clamp() [2/10]

 Float64 mi::math::clamp ( Float64 s, Float64 low, Float64 high )
inline

Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`.

## ◆ clamp() [3/10]

 Sint16 mi::math::clamp ( Sint16 s, Sint16 low, Sint16 high )
inline

Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`.

## ◆ clamp() [4/10]

 Sint32 mi::math::clamp ( Sint32 s, Sint32 low, Sint32 high )
inline

Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`.

## ◆ clamp() [5/10]

 Sint64 mi::math::clamp ( Sint64 s, Sint64 low, Sint64 high )
inline

Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`.

## ◆ clamp() [6/10]

 Sint8 mi::math::clamp ( Sint8 s, Sint8 low, Sint8 high )
inline

Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`.

## ◆ clamp() [7/10]

 Uint16 mi::math::clamp ( Uint16 s, Uint16 low, Uint16 high )
inline

Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`.

## ◆ clamp() [8/10]

 Uint32 mi::math::clamp ( Uint32 s, Uint32 low, Uint32 high )
inline

Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`.

## ◆ clamp() [9/10]

 Uint64 mi::math::clamp ( Uint64 s, Uint64 low, Uint64 high )
inline

Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`.

## ◆ clamp() [10/10]

 Uint8 mi::math::clamp ( Uint8 s, Uint8 low, Uint8 high )
inline

Returns the value `s` if it is in the range [`low`, `high`], the value `low` if `s` < `low`, or the value `high` if `s` > `high`.

## ◆ cos() [1/2]

 Float32 mi::math::cos ( Float32 a )
inline

Returns the cosine of `a`. The angle `a` is specified in radians.

## ◆ cos() [2/2]

 Float64 mi::math::cos ( Float64 a )
inline

Returns the cosine of `a`. The angle `a` is specified in radians.

## ◆ degrees() [1/2]

 Float32 mi::math::degrees ( Float32 r )
inline

Converts radians `r` to degrees.

## ◆ degrees() [2/2]

 Float64 mi::math::degrees ( Float64 r )
inline

Converts radians `r` to degrees.

## ◆ dot() [1/4]

template<class V>
 V::value_type mi::math::dot ( const V & lhs, const V & rhs )
inline

Returns the inner product (a.k.a. dot or scalar product) of two vectors.

## ◆ dot() [2/4]

 Float32 mi::math::dot ( Float32 a, Float32 b )
inline

Returns the inner product (a.k.a. dot or scalar product) of two scalars.

## ◆ dot() [3/4]

 Float64 mi::math::dot ( Float64 a, Float64 b )
inline

Returns the inner product (a.k.a. dot or scalar product) of two scalars.

## ◆ dot() [4/4]

 Sint32 mi::math::dot ( Sint32 a, Sint32 b )
inline

Returns the inner product (a.k.a. dot or scalar product) of two integers.

## ◆ euclidean_distance()

template<class V>
 V::value_type mi::math::euclidean_distance ( const V & lhs, const V & rhs )
inline

Returns the Euclidean distance from the vector `lhs` to the vector `rhs`.

Uses an unqualified call to `sqrt(...)` on the vector element type.

## ◆ exp2() [1/2]

 Float32 mi::math::exp2 ( Float32 s )
inline

Returns the constant `2` to the power of `s` (exponential function).

## ◆ exp2() [2/2]

 Float64 mi::math::exp2 ( Float64 s )
inline

Returns the constant `2` to the power of `s` (exponential function).

## ◆ fast_exp()

 Float32 mi::math::fast_exp ( Float32 x )
inline

A fast implementation of exp for floats.

## ◆ fast_log2()

 Float32 mi::math::fast_log2 ( Float32 i )
inline

A fast implementation of log2(x) for floats.

## ◆ fast_pow()

 Float32 mi::math::fast_pow ( Float32 b, Float32 e )
inline

A fast implementation of pow(x,y) for floats.

Parameters
 b base e exponent

## ◆ fast_pow2()

 Float32 mi::math::fast_pow2 ( Float32 x )
inline

A fast implementation of pow(2,x) for floats.

## ◆ fast_sqrt()

 Float32 mi::math::fast_sqrt ( Float32 i )
inline

A fast implementation of sqrt(x) for floats.

## ◆ floor() [1/2]

 Float32 mi::math::floor ( Float32 s )
inline

Returns the largest integral value that is not greater than `s`.

## ◆ floor() [2/2]

 Float64 mi::math::floor ( Float64 s )
inline

Returns the largest integral value that is not greater than `s`.

## ◆ fmod() [1/2]

 Float32 mi::math::fmod ( Float32 a, Float32 b )
inline

Returns `a` modulo `b`, in other words, the remainder of a/b.

The result has the same sign as `a`.

## ◆ fmod() [2/2]

 Float64 mi::math::fmod ( Float64 a, Float64 b )
inline

Returns `a` modulo `b`, in other words, the remainder of a/b.

The result has the same sign as `a`.

## ◆ frac() [1/2]

 Float32 mi::math::frac ( Float32 s )
inline

Returns the positive fractional part of `s`.

## ◆ frac() [2/2]

 Float64 mi::math::frac ( Float64 s )
inline

Returns the positive fractional part of `s`.

## ◆ from_rgbe() [1/2]

 MI_HOST_DEVICE_INLINE void mi::math::from_rgbe ( const Uint32 rgbe, Float32 color[3] )

Decodes a color from RGBE representation.

## ◆ from_rgbe() [2/2]

 MI_HOST_DEVICE_INLINE void mi::math::from_rgbe ( const Uint8 rgbe[4], Float32 color[3] )

Decodes a color from RGBE representation.

## ◆ is_approx_equal() [1/2]

 bool mi::math::is_approx_equal ( Float32 left, Float32 right, Float32 e )
inline

Compares the two given values for equality within the given epsilon.

## ◆ is_approx_equal() [2/2]

 bool mi::math::is_approx_equal ( Float64 left, Float64 right, Float64 e )
inline

Compares the two given values for equality within the given epsilon.

## ◆ is_equal()

template<class V>
 bool mi::math::is_equal ( const V & lhs, const V & rhs )
inline

Returns `true` if vector `lhs` is elementwise equal to vector `rhs`, and `false` otherwise.

## ◆ is_not_equal()

template<class V>
 bool mi::math::is_not_equal ( const V & lhs, const V & rhs )
inline

Returns `true` if vector `lhs` is elementwise not equal to vector `rhs`, and `false` otherwise.

## ◆ isinfinite() [1/2]

 bool mi::math::isinfinite ( const Float32 x )
inline

Checks a single-precision floating point number for "infinity".

The methods relies on the IEEE 754 floating-point standard.

## ◆ isinfinite() [2/2]

 bool mi::math::isinfinite ( const Float64 x )
inline

Checks a double-precision floating point number for "infinity".

The methods relies on the IEEE 754 floating-point standard.

 Uint32 mi::math::leading_zeros ( Uint32 v )
inline

Returns the number of leading zeros of `v`, 32-bit version.

 Uint32 mi::math::leading_zeros ( Uint64 v )
inline

Returns the number of leading zeros of `v`, 64-bit version.

## ◆ length() [1/3]

template<class V>
 V::value_type mi::math::length ( const V & v )
inline

Returns the Euclidean norm of the vector `v`.

Uses an unqualified call to `sqrt(...)` on the vector element type.

## ◆ length() [2/3]

 Float32 mi::math::length ( Float32 a )
inline

Returns the Euclidean norm of the scalar `a` (its absolute value).

## ◆ length() [3/3]

 Float64 mi::math::length ( Float64 a )
inline

Returns the Euclidean norm of the scalar `a` (its absolute value).

## ◆ lerp() [1/2]

 Float32 mi::math::lerp ( Float32 s1, Float32 s2, Float32 t )
inline

Returns the linear interpolation between `s1` and `s2`, i.e., it returns `(1-t) * s1 + t * s2`.

Parameters
 s1 one scalar s2 second scalar t interpolation parameter in [0,1]

## ◆ lerp() [2/2]

 Float64 mi::math::lerp ( Float64 s1, Float64 s2, Float64 t )
inline

Returns the linear interpolation between `s1` and `s2`, i.e., it returns `(1-t) * s1 + t * s2`.

Parameters
 s1 one scalar s2 second scalar t interpolation parameter in [0,1]

## ◆ lexicographically_compare()

template<class V>
 Comparison_result mi::math::lexicographically_compare ( const V & lhs, const V & rhs )
inline

Compares two vectors lexicographically.

Returns `LESS` if `lhs` is less than `rhs`, and correspondingly `EQUAL` or `GREATER` for the other cases.

Note
The result of this function is undefined if `lhs` or `rhs` contains NaNs.
mi::Comparison_result, Definition: Lexicographic order and comparison

## ◆ lexicographically_greater()

template<class V>
 bool mi::math::lexicographically_greater ( const V & lhs, const V & rhs )
inline

Returns `true` if vector `lhs` is lexicographically greater than vector `rhs`, and `false` otherwise.

Definition: Lexicographic order and comparison

## ◆ lexicographically_greater_or_equal()

template<class V>
 bool mi::math::lexicographically_greater_or_equal ( const V & lhs, const V & rhs )
inline

Returns `true` if vector `lhs` is lexicographically greater than or equal to vector `rhs`, and `false` otherwise.

Definition: Lexicographic order and comparison

## ◆ lexicographically_less()

template<class V>
 bool mi::math::lexicographically_less ( const V & lhs, const V & rhs )
inline

Returns `true` if vector `lhs` is lexicographically less than vector `rhs`, and `false` otherwise.

Definition: Lexicographic order and comparison

## ◆ lexicographically_less_or_equal()

template<class V>
 bool mi::math::lexicographically_less_or_equal ( const V & lhs, const V & rhs )
inline

Returns `true` if vector `lhs` is lexicographically less than or equal to vector `rhs`, and `false` otherwise.

Definition: Lexicographic order and comparison

## ◆ log10() [1/2]

 Float32 mi::math::log10 ( Float32 s )
inline

Returns the base 10 logarithm of `s`.

## ◆ log10() [2/2]

 Float64 mi::math::log10 ( Float64 s )
inline

Returns the base 10 logarithm of `s`.

## ◆ log2() [1/2]

 Float32 mi::math::log2 ( Float32 s )
inline

Returns the base 2 logarithm of `s`.

## ◆ log2() [2/2]

 Float64 mi::math::log2 ( Float64 s )
inline

Returns the base 2 logarithm of `s`.

## ◆ log2_int() [1/4]

 Sint32 mi::math::log2_int ( const Float32 v )
inline

Returns the integer log2 of `v`.

## ◆ log2_int() [2/4]

 Sint32 mi::math::log2_int ( const Float64 v )
inline

Returns the integer log2 of `v`.

## ◆ log2_int() [3/4]

 Sint32 mi::math::log2_int ( const Uint32 v )
inline

Returns the integer log2 of `v`.

## ◆ log2_int() [4/4]

 Sint32 mi::math::log2_int ( const Uint64 v )
inline

Returns the integer log2 of `v`.

## ◆ log2_int_ceil()

template<typename Integer>
 Sint32 mi::math::log2_int_ceil ( const Integer v )
inline

Returns the integer log2 of `v`, i.e., rounded up to the next integer.

## ◆ modf() [1/2]

 Float32 mi::math::modf ( Float32 s, Float32 & i )
inline

Returns the fractional part of `s` and stores the integral part of `s` in `i`.

Both parts have the same sign as `s`.

## ◆ modf() [2/2]

 Float64 mi::math::modf ( Float64 s, Float64 & i )
inline

Returns the fractional part of `s` and stores the integral part of `s` in `i`.

Both parts have the same sign as `s`.

## ◆ pow() [1/6]

 Float32 mi::math::pow ( Float32 a, Float32 b )
inline

Returns `a` to the power of `b`.

## ◆ pow() [2/6]

 Float64 mi::math::pow ( Float64 a, Float64 b )
inline

Returns `a` to the power of `b`.

## ◆ pow() [3/6]

 Sint32 mi::math::pow ( Sint32 a, Sint32 b )
inline

Returns `a` to the power of `b`.

## ◆ pow() [4/6]

 Sint64 mi::math::pow ( Sint64 a, Sint64 b )
inline

Returns `a` to the power of `b`.

## ◆ pow() [5/6]

 Uint32 mi::math::pow ( Uint32 a, Uint32 b )
inline

Returns `a` to the power of `b`.

## ◆ pow() [6/6]

 Uint64 mi::math::pow ( Uint64 a, Uint64 b )
inline

Returns `a` to the power of `b`.

 Float32 mi::math::radians ( Float32 d )
inline

Converts degrees `d` to radians.

 Float64 mi::math::radians ( Float64 d )
inline

Converts degrees `d` to radians.

## ◆ round() [1/2]

 Float32 mi::math::round ( Float32 s )
inline

Returns `s` rounded to the nearest integer value.

## ◆ round() [2/2]

 Float64 mi::math::round ( Float64 s )
inline

Returns `s` rounded to the nearest integer value.

## ◆ rsqrt() [1/2]

 Float32 mi::math::rsqrt ( Float32 s )
inline

Returns the reciprocal of the square root of `s`.

## ◆ rsqrt() [2/2]

 Float64 mi::math::rsqrt ( Float64 s )
inline

Returns the reciprocal of the square root of `s`.

## ◆ saturate() [1/2]

 Float32 mi::math::saturate ( Float32 s )
inline

Returns the value `s` clamped to the range [0,1].

## ◆ saturate() [2/2]

 Float64 mi::math::saturate ( Float64 s )
inline

Returns the value `s` clamped to the range [0,1].

## ◆ set_bounds()

template<class V>
 void mi::math::set_bounds ( V & v, const V & low, const V & high )
inline

Bounds the value of vector `v` elementwise to the given `low` and `high` vector values.

## ◆ sign() [1/6]

 Float32 mi::math::sign ( Float32 s )
inline

Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`.

## ◆ sign() [2/6]

 Float64 mi::math::sign ( Float64 s )
inline

Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`.

## ◆ sign() [3/6]

 Sint16 mi::math::sign ( Sint16 s )
inline

Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`.

## ◆ sign() [4/6]

 Sint32 mi::math::sign ( Sint32 s )
inline

Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`.

## ◆ sign() [5/6]

 Sint64 mi::math::sign ( Sint64 s )
inline

Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`.

## ◆ sign() [6/6]

 Sint8 mi::math::sign ( Sint8 s )
inline

Returns -1 if `s<0`, 0 if `s==0`, and +1 if `s>0`.

## ◆ sign_bit() [1/6]

 bool mi::math::sign_bit ( Float32 s )
inline

Extracts the sign bit of a single-precision floating point number.

The methods relies on the IEEE 754 floating-point standard. Note that the sign bit is set for the special floating-point value -0.0f, so this function returns `true` for this value.

## ◆ sign_bit() [2/6]

 bool mi::math::sign_bit ( Float64 s )
inline

Extracts the sign bit of a double-precision floating point number.

The methods relies on the IEEE 754 floating-point standard. Note that the sign bit is set for the special floating-point value -0.0f, so this function returns `true` for this value.

## ◆ sign_bit() [3/6]

 bool mi::math::sign_bit ( Sint16 s )
inline

Returns `true` if `s<0` and `false` if `s>=` 0.

## ◆ sign_bit() [4/6]

 bool mi::math::sign_bit ( Sint32 s )
inline

Returns `true` if `s<0` and `false` if `s>=` 0.

## ◆ sign_bit() [5/6]

 bool mi::math::sign_bit ( Sint64 s )
inline

Returns `true` if `s<0` and `false` if `s>=` 0.

## ◆ sign_bit() [6/6]

 bool mi::math::sign_bit ( Sint8 s )
inline

Returns `true` if `s<0` and `false` if `s>=` 0.

## ◆ sin() [1/2]

 Float32 mi::math::sin ( Float32 a )
inline

Returns the sine of `a`. The angle `a` is specified in radians.

## ◆ sin() [2/2]

 Float64 mi::math::sin ( Float64 a )
inline

Returns the sine of `a`. The angle `a` is specified in radians.

## ◆ sincos() [1/2]

 void mi::math::sincos ( Float32 a, Float32 & s, Float32 & c )
inline

Computes the sine `s` and cosine `c` of angle `a` simultaneously.

The angle `a` is specified in radians.

## ◆ sincos() [2/2]

 void mi::math::sincos ( Float64 a, Float64 & s, Float64 & c )
inline

Computes the sine `s` and cosine `c` of angle `a` simultaneously.

The angle `a` is specified in radians.

## ◆ smoothstep() [1/2]

 Float32 mi::math::smoothstep ( Float32 a, Float32 b, Float32 x )
inline

Returns 0 if `x` is less than `a` and 1 if `x` is greater than `b`.

A smooth curve is applied in-between so that the return value varies continuously from 0 to 1 as `x` varies from `a` to `b`.

## ◆ smoothstep() [2/2]

 Float64 mi::math::smoothstep ( Float64 a, Float64 b, Float64 x )
inline

Returns 0 if `x` is less than `a` and 1 if `x` is greater than `b`.

A smooth curve is applied in-between so that the return value varies continuously from 0 to 1 as `x` varies from `a` to `b`.

## ◆ sqrt() [1/2]

 Float32 mi::math::sqrt ( Float32 s )
inline

Returns the square root of `s`.

## ◆ sqrt() [2/2]

 Float64 mi::math::sqrt ( Float64 s )
inline

Returns the square root of `s`.

## ◆ square_euclidean_distance()

template<class V>
 V::value_type mi::math::square_euclidean_distance ( const V & lhs, const V & rhs )
inline

Returns the squared Euclidean distance from the vector `lhs` to the vector `rhs`.

## ◆ square_length()

template<class V>
 V::value_type mi::math::square_length ( const V & v )
inline

Returns the squared Euclidean norm of the vector `v`.

## ◆ step() [1/2]

 Float32 mi::math::step ( Float32 a, Float32 x )
inline

Returns 0 if `x` is less than `a` and 1 otherwise.

## ◆ step() [2/2]

 Float64 mi::math::step ( Float64 a, Float64 x )
inline

Returns 0 if `x` is less than `a` and 1 otherwise.

## ◆ tan() [1/2]

 Float32 mi::math::tan ( Float32 a )
inline

Returns the tangent of `a`. The angle `a` is specified in radians.

## ◆ tan() [2/2]

 Float64 mi::math::tan ( Float64 a )
inline

Returns the tangent of `a`. The angle `a` is specified in radians.

## ◆ to_rgbe() [1/2]

 MI_HOST_DEVICE_INLINE void mi::math::to_rgbe ( const Float32 color[3], Uint32 & rgbe )

Encodes a color into RGBE representation.

## ◆ to_rgbe() [2/2]

 MI_HOST_DEVICE_INLINE void mi::math::to_rgbe ( const Float32 color[3], Uint8 rgbe[4] )

Encodes a color into RGBE representation.