Mathematics Functions[Math]

13 Mathematics Functions[Math]

This clause lists and describes functions provided by the HLSL standard library to work with numeric data and perform mathematical operations.

13.1 General Functions[Math.GeneralFunctions]

This subclause lists and describes functions for general mathematics operations operating objects of integer types, floating-point types, and vectors of such types.

float16_t abs(float16_t x); float abs(float x); double abs(double x); int16_t abs(int16_t x); uint16_t abs(uint16_t x); int abs(int x); uint abs(uint x); int64_t abs(int64_t x); uint64_t abs(uint64_t x); template <uint N> vector<float16_t, N> abs(vector<float16_t, N> x); template <uint N> vector<float, N> abs(vector<float, N> x); template <uint N> vector<double, N> abs(vector<double, N> x); template <uint N> vector<int16_t, N> abs(vector<int16_t, N> x); template <uint N> vector<uint16_t, N> abs(vector<uint16_t, N> x); template <uint N> vector<int, N> abs(vector<int, N> x); template <uint N> vector<uint, N> abs(vector<uint, N> x); template <uint N> vector<int64_t, N> abs(vector<int64_t, N> x); template <uint N> vector<uint64_t, N> abs(vector<uint64_t, N> x);

float16_t ceil(float16_t x); float ceil(float x); template <uint N> vector<float16_t, N> ceil(vector<float16_t, N> x); template <uint N> vector<float, N> ceil(vector<float, N> x);

float16_t clamp(float16_t x, float16_t min, float16_t max); float clamp(float x, float min, float max); double clamp(double x, double min, double max); int16_t clamp(int16_t x, int16_t min, int16_t max); uint16_t clamp(uint16_t x, uint16_t min, uint16_t max); int clamp(int x, int min, int max); uint clamp(uint x, uint min, uint max); int64_t clamp(int64_t x, int64_t min, int64_t max); uint64_t clamp(uint64_t x, uint64_t min, uint64_t max); template <uint N> vector<float16_t, N> clamp(vector<float16_t, N> x, vector<float16_t, N> min, vector<float16_t, N> max); template <uint N> vector<float, N> clamp(vector<float, N> x, vector<float, N> min, vector<float, N> max); template <uint N> vector<double, N> clamp(vector<double, N> x, vector<double, N> min, vector<double, N> max); template <uint N> vector<int16_t, N> clamp(vector<int16_t, N> x, vector<int16_t, N> min, vector<int16_t, N> max); template <uint N> vector<uint16_t, N> clamp(vector<uint16_t, N> x, vector<uint16_t, N> min, vector<uint16_t, N> max); template <uint N> vector<int, N> clamp(vector<int, N> x, vector<int, N> min, vector<int, N> max); template <uint N> vector<uint, N> clamp(vector<uint, N> x, vector<uint, N> min, vector<uint, N> max); template <uint N> vector<int64_t, N> clamp(vector<int64_t, N> x, vector<int64_t, N> min, vector<int64_t, N> max); template <uint N> vector<uint64_t, N> clamp(vector<uint64_t, N> x, vector<uint64_t, N> min, vector<uint64_t, N> max);

float16_t exp(float16_t x); float exp(float x); template <uint N> vector<float16_t, N> exp(vector<float16_t, N> x); template <uint N> vector<float, N> exp(vector<float, N> x);

float16_t exp2(float16_t x); float exp2(float x); template <uint N> vector<float16_t, N> exp2(vector<float16_t, N> x); template <uint N> vector<float, N> exp2(vector<float, N> x);

float16_t floor(float16_t x); float floor(float x); template <uint N> vector<float16_t, N> floor(vector<float16_t, N> x); template <uint N> vector<float, N> floor(vector<float, N> x);

double fma(double a, double b, double c); template <uint N> vector<double, N> fma(vector<double, N> a, vector<double, N> b, vector<double, N> c);

float16_t fmod(float16_t a, float16_t b); float fmod(float a, float b); template <uint N> vector<float16_t, N> fmod(vector<float16_t, N> a, vector<float16_t, N> b); template <uint N> vector<float, N> fmod(vector<float, N> a, vector<float, N> b);

float16_t frac(float16_t x); float frac(float x); template <uint N> vector<float16_t, N> frac(vector<float16_t, N> x); template <uint N> vector<float, N> frac(vector<float, N> x);

float frexp(float x, out float exp); template <uint N> vector<float, N> frexp(vector<float, N> x, out vector<float, N> exp);

float16_t ldexp(float16_t x, float16_t exp); float ldexp(float x, float exp); template <uint N> vector<float16_t, N> ldexp(vector<float16_t, N> x, vector<float16_t, N> exp); template <uint N> vector<float, N> ldexp(vector<float, N> x, vector<float, N> exp);

float16_t lerp(float16_t a, float16_t b, float16_t s); float lerp(float a, float b, float s); template <uint N> vector<float16_t, N> lerp(vector<float16_t, N> a, vector<float16_t, N> b, vector<float16_t, N> s); template <uint N> vector<float, N> lerp(vector<float, N> a, vector<float, N> b, vector<float, N> s);

float16_t log(float16_t x); float log(float x); template <uint N> vector<float16_t, N> log(vector<float16_t, N> x); template <uint N> vector<float, N> log(vector<float, N> x);

float16_t log10(float16_t x); float log10(float x); template <uint N> vector<float16_t, N> log10(vector<float16_t, N> x); template <uint N> vector<float, N> log10(vector<float, N> x);

float16_t log2(float16_t x); float log2(float x); template <uint N> vector<float16_t, N> log2(vector<float16_t, N> x); template <uint N> vector<float, N> log2(vector<float, N> x);

float16_t mad(float16_t a, float16_t b, float16_t c); float mad(float a, float b, float c); double mad(double a, double b, double c); int16_t mad(int16_t a, int16_t b, int16_t c); uint16_t mad(uint16_t a, uint16_t b, uint16_t c); int mad(int a, int b, int c); uint mad(uint a, uint b, uint c); int64_t mad(int64_t a, int64_t b, int64_t c); uint64_t mad(uint64_t a, uint64_t b, uint64_t c); template <uint N> vector<float16_t, N> mad(vector<float16_t, N> a, vector<float16_t, N> b, vector<float16_t, N> c); template <uint N> vector<float, N> mad(vector<float, N> a, vector<float, N> b, vector<float, N> c); template <uint N> vector<double, N> mad(vector<double, N> a, vector<double, N> b, vector<double, N> c); template <uint N> vector<int16_t, N> mad(vector<int16_t, N> a, vector<int16_t, N> b, vector<int16_t, N> c); template <uint N> vector<uint16_t, N> mad(vector<uint16_t, N> a, vector<uint16_t, N> b, vector<uint16_t, N> c); template <uint N> vector<int, N> mad(vector<int, N> a, vector<int, N> b, vector<int, N> c); template <uint N> vector<uint, N> mad(vector<uint, N> a, vector<uint, N> b, vector<uint, N> c); template <uint N> vector<int64_t, N> mad(vector<int64_t, N> a, vector<int64_t, N> b, vector<int64_t, N> c); template <uint N> vector<uint64_t, N> mad(vector<uint64_t, N> a, vector<uint64_t, N> b, vector<uint64_t, N> c);

float16_t max(float16_t a, float16_t b); float max(float a, float b); double max(double a, double b); int16_t max(int16_t a, int16_t b); uint16_t max(uint16_t a, uint16_t b); int max(int a, int b); uint max(uint a, uint b); int64_t max(int64_t a, int64_t b); uint64_t max(uint64_t a, uint64_t b); template <uint N> vector<float16_t, N> max(vector<float16_t, N> a, vector<float16_t, N> b); template <uint N> vector<float, N> max(vector<float, N> a, vector<float, N> b); template <uint N> vector<double, N> max(vector<double, N> a, vector<double, N> b); template <uint N> vector<int16_t, N> max(vector<int16_t, N> a, vector<int16_t, N> b); template <uint N> vector<uint16_t, N> max(vector<uint16_t, N> a, vector<uint16_t, N> b); template <uint N> vector<int, N> max(vector<int, N> a, vector<int, N> b); template <uint N> vector<uint, N> max(vector<uint, N> a, vector<uint, N> b); template <uint N> vector<int64_t, N> max(vector<int64_t, N> a, vector<int64_t, N> b); template <uint N> vector<uint64_t, N> max(vector<uint64_t, N> a, vector<uint64_t, N> b);

float16_t min(float16_t a, float16_t b); float min(float a, float b); double min(double a, double b); int16_t min(int16_t a, int16_t b); uint16_t min(uint16_t a, uint16_t b); int min(int a, int b); uint min(uint a, uint b); int64_t min(int64_t a, int64_t b); uint64_t min(uint64_t a, uint64_t b); template <uint N> vector<float16_t, N> min(vector<float16_t, N> a, vector<float16_t, N> b); template <uint N> vector<float, N> min(vector<float, N> a, vector<float, N> b); template <uint N> vector<double, N> min(vector<double, N> a, vector<double, N> b); template <uint N> vector<int16_t, N> min(vector<int16_t, N> a, vector<int16_t, N> b); template <uint N> vector<uint16_t, N> min(vector<uint16_t, N> a, vector<uint16_t, N> b); template <uint N> vector<int, N> min(vector<int, N> a, vector<int, N> b); template <uint N> vector<uint, N> min(vector<uint, N> a, vector<uint, N> b); template <uint N> vector<int64_t, N> min(vector<int64_t, N> a, vector<int64_t, N> b); template <uint N> vector<uint64_t, N> min(vector<uint64_t, N> a, vector<uint64_t, N> b);

float16_t pow(float16_t x, float16_t y); float pow(float x, float y); template <uint N> vector<float16_t, N> pow(vector<float16_t, N> x, vector<float16_t, N> y); template <uint N> vector<float, N> pow(vector<float, N> x, vector<float, N> y);

float16_t rcp(float16_t x); float rcp(float x); double rcp(double x); template <uint N> vector<float16_t, N> rcp(vector<float16_t, N> x); template <uint N> vector<float, N> rcp(vector<float, N> x); template <uint N> vector<double, N> rcp(vector<double, N> x);

float16_t round(float16_t x); float round(float x); template <uint N> vector<float16_t, N> round(vector<float16_t, N> x); template <uint N> vector<float, N> round(vector<float, N> x);

float16_t rsqrt(float16_t x); float rsqrt(float x); template <uint N> vector<float16_t, N> rsqrt(vector<float16_t, N> x); template <uint N> vector<float, N> rsqrt(vector<float, N> x);

int sign(float16_t x); int sign(float x); int sign(double x); int sign(int16_t x); int sign(uint16_t x); int sign(int x); int sign(uint x); int sign(int64_t x); int sign(uint64_t x); template <uint N> vector<int, N> sign(vector<float16_t, N> x); template <uint N> vector<int, N> sign(vector<float, N> x); template <uint N> vector<int, N> sign(vector<double, N> x); template <uint N> vector<int, N> sign(vector<int16_t, N> x); template <uint N> vector<int, N> sign(vector<uint16_t, N> x); template <uint N> vector<int, N> sign(vector<int, N> x); template <uint N> vector<int, N> sign(vector<uint, N> x); template <uint N> vector<int, N> sign(vector<int64_t, N> x); template <uint N> vector<int, N> sign(vector<uint64_t, N> x);

float16_t smoothstep(float16_t a, float16_t b, float16_t x); float smoothstep(float a, float b, float x); template <uint N> vector<float16_t, N> smoothstep(vector<float16_t, N> a, vector<float16_t, N> b, vector<float16_t, N> x); template <uint N> vector<float, N> smoothstep(vector<float, N> a, vector<float, N> b, vector<float, N> x);

float16_t sqrt(float16_t x); float sqrt(float x); template <uint N> vector<float16_t, N> sqrt(vector<float16_t, N> x); template <uint N> vector<float, N> sqrt(vector<float, N> x);

float16_t step(float16_t a, float16_t x); float step(float a, float x); template <uint N> vector<float16_t, N> step(vector<float16_t, N> a, vector<float16_t, N> x); template <uint N> vector<float, N> step(vector<float, N> a, vector<float, N> x);

float16_t trunc(float16_t x); float trunc(float x); template <uint N> vector<float16_t, N> trunc(vector<float16_t, N> x); template <uint N> vector<float, N> trunc(vector<float, N> x);

13.1.1 Other Non-Member Functions[Math.GeneralFunctions.Other]

float16_t abs(float16_t x); float abs(float x); double abs(double x); int16_t abs(int16_t x); uint16_t abs(uint16_t x); int abs(int x); uint abs(uint x); int64_t abs(int64_t x); uint64_t abs(uint64_t x); template <uint N> vector<float16_t, N> abs(vector<float16_t, N> x); template <uint N> vector<float, N> abs(vector<float, N> x); template <uint N> vector<double, N> abs(vector<double, N> x); template <uint N> vector<int16_t, N> abs(vector<int16_t, N> x); template <uint N> vector<uint16_t, N> abs(vector<uint16_t, N> x); template <uint N> vector<int, N> abs(vector<int, N> x); template <uint N> vector<uint, N> abs(vector<uint, N> x); template <uint N> vector<int64_t, N> abs(vector<int64_t, N> x); template <uint N> vector<uint64_t, N> abs(vector<uint64_t, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the magnitude of the corresponding input element (|x0|, ..|xn|).

float16_t ceil(float16_t x); float ceil(float x); template <uint N> vector<float16_t, N> ceil(vector<float16_t, N> x); template <uint N> vector<float, N> ceil(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the ceiling of the corresponding input element (⌈x0⌉, ..⌈xn⌉).

float16_t clamp(float16_t x, float16_t min, float16_t max); float clamp(float x, float min, float max); double clamp(double x, double min, double max); int16_t clamp(int16_t x, int16_t min, int16_t max); uint16_t clamp(uint16_t x, uint16_t min, uint16_t max); int clamp(int x, int min, int max); uint clamp(uint x, uint min, uint max); int64_t clamp(int64_t x, int64_t min, int64_t max); uint64_t clamp(uint64_t x, uint64_t min, uint64_t max); template <uint N> vector<float16_t, N> clamp(vector<float16_t, N> x, vector<float16_t, N> min, vector<float16_t, N> max); template <uint N> vector<float, N> clamp(vector<float, N> x, vector<float, N> min, vector<float, N> max); template <uint N> vector<double, N> clamp(vector<double, N> x, vector<double, N> min, vector<double, N> max); template <uint N> vector<int16_t, N> clamp(vector<int16_t, N> x, vector<int16_t, N> min, vector<int16_t, N> max); template <uint N> vector<uint16_t, N> clamp(vector<uint16_t, N> x, vector<uint16_t, N> min, vector<uint16_t, N> max); template <uint N> vector<int, N> clamp(vector<int, N> x, vector<int, N> min, vector<int, N> max); template <uint N> vector<uint, N> clamp(vector<uint, N> x, vector<uint, N> min, vector<uint, N> max); template <uint N> vector<int64_t, N> clamp(vector<int64_t, N> x, vector<int64_t, N> min, vector<int64_t, N> max); template <uint N> vector<uint64_t, N> clamp(vector<uint64_t, N> x, vector<uint64_t, N> min, vector<uint64_t, N> max);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is clamped between the corresponding value in the min and max inputs.

  • Remarks: Behavior of NaN input values is undefined.

float16_t exp(float16_t x); float exp(float x); template <uint N> vector<float16_t, N> exp(vector<float16_t, N> x); template <uint N> vector<float, N> exp(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the base e exponent of the corresponding element (ex0, ..exn).

float16_t exp2(float16_t x); float exp2(float x); template <uint N> vector<float16_t, N> exp2(vector<float16_t, N> x); template <uint N> vector<float, N> exp2(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the base 2 exponent of the corresponding element (2x0, ..2xn).

float16_t floor(float16_t x); float floor(float x); template <uint N> vector<float16_t, N> floor(vector<float16_t, N> x); template <uint N> vector<float, N> floor(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the floor of the corresponding input element (⌊x0⌋, ..⌊xn⌋).

double fma(double a, double b, double c); template <uint N> vector<double, N> fma(vector<double, N> a, vector<double, N> b, vector<double, N> c);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is a fused multiply add of the corresponding input elements (a0 * b0 + c0, ..an * bn + cn).

  • Remarks: The returned value must be accurate to 0.5 units of least precision (ULP).

float16_t fmod(float16_t a, float16_t b); float fmod(float a, float b); template <uint N> vector<float16_t, N> fmod(vector<float16_t, N> a, vector<float16_t, N> b); template <uint N> vector<float, N> fmod(vector<float, N> a, vector<float, N> b);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the floating-point remainder of the corresponding input elements.

float16_t frac(float16_t x); float frac(float x); template <uint N> vector<float16_t, N> frac(vector<float16_t, N> x); template <uint N> vector<float, N> frac(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the floating-point fractional component of the corresponding input elements.

float frexp(float x, out float exp); template <uint N> vector<float, N> frexp(vector<float, N> x, out vector<float, N> exp);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the mantissa of the corresponding input elements.

  • Returns: The scalar or vector exp is of the same dimensions as the input and the value of each element is initialized to the exponent of the corresponding input elements.

float16_t ldexp(float16_t x, float16_t exp); float ldexp(float x, float exp); template <uint N> vector<float16_t, N> ldexp(vector<float16_t, N> x, vector<float16_t, N> exp); template <uint N> vector<float, N> ldexp(vector<float, N> x, vector<float, N> exp);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the input element multiplied by the base 2 exponent of the corresponding element of exp (x0 * 2exp0, ..xn * 2expn).

float16_t lerp(float16_t a, float16_t b, float16_t s); float lerp(float a, float b, float s); template <uint N> vector<float16_t, N> lerp(vector<float16_t, N> a, vector<float16_t, N> b, vector<float16_t, N> s); template <uint N> vector<float, N> lerp(vector<float, N> a, vector<float, N> b, vector<float, N> s);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the linear interpolation of the corresponding input a towards b by the step factor s (a0 + s0(b0−a0), ..an + sn(bn−an)).

float16_t log(float16_t x); float log(float x); template <uint N> vector<float16_t, N> log(vector<float16_t, N> x); template <uint N> vector<float, N> log(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the base e logarithm of the corresponding element (ln x0, ..ln xn).

float16_t log10(float16_t x); float log10(float x); template <uint N> vector<float16_t, N> log10(vector<float16_t, N> x); template <uint N> vector<float, N> log10(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the base 10 logarithm of the corresponding element (log10x0, ..log10xn).

float16_t log2(float16_t x); float log2(float x); template <uint N> vector<float16_t, N> log2(vector<float16_t, N> x); template <uint N> vector<float, N> log2(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the base 2 logarithm of the corresponding element (log2x0, ..log2xn).

float16_t mad(float16_t a, float16_t b, float16_t c); float mad(float a, float b, float c); double mad(double a, double b, double c); int16_t mad(int16_t a, int16_t b, int16_t c); uint16_t mad(uint16_t a, uint16_t b, uint16_t c); int mad(int a, int b, int c); uint mad(uint a, uint b, uint c); int64_t mad(int64_t a, int64_t b, int64_t c); uint64_t mad(uint64_t a, uint64_t b, uint64_t c); template <uint N> vector<float16_t, N> mad(vector<float16_t, N> a, vector<float16_t, N> b, vector<float16_t, N> c); template <uint N> vector<float, N> mad(vector<float, N> a, vector<float, N> b, vector<float, N> c); template <uint N> vector<double, N> mad(vector<double, N> a, vector<double, N> b, vector<double, N> c); template <uint N> vector<int16_t, N> mad(vector<int16_t, N> a, vector<int16_t, N> b, vector<int16_t, N> c); template <uint N> vector<uint16_t, N> mad(vector<uint16_t, N> a, vector<uint16_t, N> b, vector<uint16_t, N> c); template <uint N> vector<int, N> mad(vector<int, N> a, vector<int, N> b, vector<int, N> c); template <uint N> vector<uint, N> mad(vector<uint, N> a, vector<uint, N> b, vector<uint, N> c); template <uint N> vector<int64_t, N> mad(vector<int64_t, N> a, vector<int64_t, N> b, vector<int64_t, N> c); template <uint N> vector<uint64_t, N> mad(vector<uint64_t, N> a, vector<uint64_t, N> b, vector<uint64_t, N> c);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is a multiplication then addition of the corresponding input elements (a0 * b0 + c0, ..an * bn + cn).

  • Remarks: An implementation may either fuse the multiplication and addition into a single operation which may avoid intermediate rounding in the result or it may implement the operation as separate multiplication and addition operations.

  • Remarks: In the presence of the precise keyword an implementation must lower all mad functions with precise outputs to the same hardware operations, which may be fused or non-fused.

float16_t max(float16_t a, float16_t b); float max(float a, float b); double max(double a, double b); int16_t max(int16_t a, int16_t b); uint16_t max(uint16_t a, uint16_t b); int max(int a, int b); uint max(uint a, uint b); int64_t max(int64_t a, int64_t b); uint64_t max(uint64_t a, uint64_t b); template <uint N> vector<float16_t, N> max(vector<float16_t, N> a, vector<float16_t, N> b); template <uint N> vector<float, N> max(vector<float, N> a, vector<float, N> b); template <uint N> vector<double, N> max(vector<double, N> a, vector<double, N> b); template <uint N> vector<int16_t, N> max(vector<int16_t, N> a, vector<int16_t, N> b); template <uint N> vector<uint16_t, N> max(vector<uint16_t, N> a, vector<uint16_t, N> b); template <uint N> vector<int, N> max(vector<int, N> a, vector<int, N> b); template <uint N> vector<uint, N> max(vector<uint, N> a, vector<uint, N> b); template <uint N> vector<int64_t, N> max(vector<int64_t, N> a, vector<int64_t, N> b); template <uint N> vector<uint64_t, N> max(vector<uint64_t, N> a, vector<uint64_t, N> b);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the greater of the corresponding input elements (a0 > b0?a0 : b0, ..an > bn?an : bn).

float16_t min(float16_t a, float16_t b); float min(float a, float b); double min(double a, double b); int16_t min(int16_t a, int16_t b); uint16_t min(uint16_t a, uint16_t b); int min(int a, int b); uint min(uint a, uint b); int64_t min(int64_t a, int64_t b); uint64_t min(uint64_t a, uint64_t b); template <uint N> vector<float16_t, N> min(vector<float16_t, N> a, vector<float16_t, N> b); template <uint N> vector<float, N> min(vector<float, N> a, vector<float, N> b); template <uint N> vector<double, N> min(vector<double, N> a, vector<double, N> b); template <uint N> vector<int16_t, N> min(vector<int16_t, N> a, vector<int16_t, N> b); template <uint N> vector<uint16_t, N> min(vector<uint16_t, N> a, vector<uint16_t, N> b); template <uint N> vector<int, N> min(vector<int, N> a, vector<int, N> b); template <uint N> vector<uint, N> min(vector<uint, N> a, vector<uint, N> b); template <uint N> vector<int64_t, N> min(vector<int64_t, N> a, vector<int64_t, N> b); template <uint N> vector<uint64_t, N> min(vector<uint64_t, N> a, vector<uint64_t, N> b);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the lesser of the corresponding input elements (a0 < b0?a0 : b0, ..an < bn?an : bn).

float16_t pow(float16_t x, float16_t y); float pow(float x, float y); template <uint N> vector<float16_t, N> pow(vector<float16_t, N> x, vector<float16_t, N> y); template <uint N> vector<float, N> pow(vector<float, N> x, vector<float, N> y);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the corresponding x element raised to the power of the corresponding y element (x0y0, ..xnyn).

float16_t rcp(float16_t x); float rcp(float x); double rcp(double x); template <uint N> vector<float16_t, N> rcp(vector<float16_t, N> x); template <uint N> vector<float, N> rcp(vector<float, N> x); template <uint N> vector<double, N> rcp(vector<double, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the reciprocal of the corresponding input element (1/x0, ..1/xn).

float16_t round(float16_t x); float round(float x); template <uint N> vector<float16_t, N> round(vector<float16_t, N> x); template <uint N> vector<float, N> round(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the value of the corresponding input element rounded to the nearest integer. Ties are rounded to the nearest even.

float16_t rsqrt(float16_t x); float rsqrt(float x); template <uint N> vector<float16_t, N> rsqrt(vector<float16_t, N> x); template <uint N> vector<float, N> rsqrt(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the reciprocal of the square root of the corresponding input element ($1/\sqrt{x_0}, .. 1/\sqrt{x_n}$).

int sign(float16_t x); int sign(float x); int sign(double x); int sign(int16_t x); int sign(uint16_t x); int sign(int x); int sign(uint x); int sign(int64_t x); int sign(uint64_t x); template <uint N> vector<int, N> sign(vector<float16_t, N> x); template <uint N> vector<int, N> sign(vector<float, N> x); template <uint N> vector<int, N> sign(vector<double, N> x); template <uint N> vector<int, N> sign(vector<int16_t, N> x); template <uint N> vector<int, N> sign(vector<uint16_t, N> x); template <uint N> vector<int, N> sign(vector<int, N> x); template <uint N> vector<int, N> sign(vector<uint, N> x); template <uint N> vector<int, N> sign(vector<int64_t, N> x); template <uint N> vector<int, N> sign(vector<uint64_t, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the sign of the corresponding input elements. For an input element less than zero the result will be  − 1, for an input element greater than zero the result will be 1, for an input element equal to zero the result will be 0.

float16_t smoothstep(float16_t a, float16_t b, float16_t x); float smoothstep(float a, float b, float x); template <uint N> vector<float16_t, N> smoothstep(vector<float16_t, N> a, vector<float16_t, N> b, vector<float16_t, N> x); template <uint N> vector<float, N> smoothstep(vector<float, N> a, vector<float, N> b, vector<float, N> x);

  • Returns:

float16_t sqrt(float16_t x); float sqrt(float x); template <uint N> vector<float16_t, N> sqrt(vector<float16_t, N> x); template <uint N> vector<float, N> sqrt(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the square root of the corresponding input element ($\sqrt{x_0}, .. \sqrt{x_n}$).

float16_t step(float16_t a, float16_t x); float step(float a, float x); template <uint N> vector<float16_t, N> step(vector<float16_t, N> a, vector<float16_t, N> x); template <uint N> vector<float, N> step(vector<float, N> a, vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is 1 if the x element is greater than or equal to the a element; otherwise the element is 0 (a0 ≥ b0?1 : 0, ..an ≥ bn?1 : 0).

float16_t trunc(float16_t x); float trunc(float x); template <uint N> vector<float16_t, N> trunc(vector<float16_t, N> x); template <uint N> vector<float, N> trunc(vector<float, N> x);

  • Returns: A scalar or vector object of the same dimensions as the input where the value of each returned element is the truncated integer value of the corresponding input element. This rounds towards zero for all values, behaving like floor for positive values and ceil for negative values.

13.2 Conversion Functions[Math.ConversionFunctions]

This subclause lists and describes conversion functions for converting values stored in numeric types and vectors of numeric types to other numeric types or vectors of such types.

double asdouble(uint lowBits, uint highBits); template<uint N> vector<double, N> asdouble(vector<uint, N> lowBits, vector<uint, N> highBits);

float asfloat(float input); float asfloat(int input); float asfloat(uint input); template<uint N> vector<float, N> asfloat(vector<float, N> input); template<uint N> vector<float, N> asfloat(vector<int, N> input); template<uint N> vector<float, N> asfloat(vector<uint, N> input);

float16_t asfloat16(float16_t input); float16_t asfloat16(int16_t input); float16_t asfloat16(uint16_t input); template<uint N> vector<float16_t, N> asfloat16(vector<float16_t, N> input); template<uint N> vector<float16_t, N> asfloat16(vector<int16_t, N> input); template<uint N> vector<float16_t, N> asfloat16(vector<uint16_t, N> input);

int16_t asint16(float16_t input); int16_t asint16(int16_t input); int16_t asint16(uint16_t input); template<uint N> vector<int16_t, N> asint16(vector<float16_t, N> input); template<uint N> vector<int16_t, N> asint16(vector<int16_t, N> input); template<uint N> vector<int16_t, N> asint16(vector<uint16_t, N> input);

int asint(float input); int asint(int input); int asint(uint input); template<uint N> vector<int, N> asint(vector<float, N> input); template<uint N> vector<int, N> asint(vector<int, N> input); template<uint N> vector<int, N> asint(vector<uint, N> input);

void asuint(double input, out uint lowBits, out uint highBits); template<uint N> void asuint(vector<double, N> input, out vector<uint, N> lowBits, out vector<uint, N> highBits);

uint asuint(float input); uint asuint(int input); uint asuint(uint input); template<uint N> vector<uint, N> asuint(vector<float, N> input); template<uint N> vector<uint, N> asuint(vector<int, N> input); template<uint N> vector<uint, N> asuint(vector<uint, N> input);

uint16_t asuint16(float16_t input); uint16_t asuint16(int16_t input); uint16_t asuint16(uint16_t input); template<uint N> vector<uint16_t, N> asuint16(vector<float16_t, N> input); template<uint N> vector<uint16_t, N> asuint16(vector<int16_t, N> input); template<uint N> vector<uint16_t, N> asuint16(vector<uint16_t, N> input);

float f16tof32(uint input); template<uint N> vector<float, N> f16tof32(vector<uint, N> input);

uint f32tof16(float input); template<uint N> vector<uint, N> f32tof16(vector<float, N> input);

13.2.1 Other Non-Member Functions[Math.ConversionFunctions.Other]

double asdouble(uint lowBits, uint highBits); template<uint N> vector<double, N> asdouble(vector<uint, N> lowBits, vector<uint, N> highBits);

  • Requires: uint scalars or vectors lowBits and highBits must have the same dimensions.

  • Returns: A scalar or vector of the same dimension as the input vectors, containing 64-bit double values constructed by replicating the bits from each element of lowBits into the low order bits of the corresponding element of the result and the bits from each element of highBits into the high order bits of the corresponding element of the result.

  • Notes: This function allow shaders to construct double values from integers without requiring 64-bit integer support.

float asfloat(float input); float asfloat(int input); float asfloat(uint input); template<uint N> vector<float, N> asfloat(vector<float, N> input); template<uint N> vector<float, N> asfloat(vector<int, N> input); template<uint N> vector<float, N> asfloat(vector<uint, N> input);

  • Returns: A scalar or vector object of 32-bit floating point values. Each bit in the object representation of the input argument is replicated into the newly created floating-point scalar or vector return value.

float16_t asfloat16(float16_t input); float16_t asfloat16(int16_t input); float16_t asfloat16(uint16_t input); template<uint N> vector<float16_t, N> asfloat16(vector<float16_t, N> input); template<uint N> vector<float16_t, N> asfloat16(vector<int16_t, N> input); template<uint N> vector<float16_t, N> asfloat16(vector<uint16_t, N> input);

  • Returns: A scalar or vector object of 16-bit floating point values. Each bit in the object representation of the input argument is replicated into the newly created floating-point scalar or vector return value.

  • Remarks: An implementation will only provide this function if it supports native 16-bit data types.

int16_t asint16(float16_t input); int16_t asint16(int16_t input); int16_t asint16(uint16_t input); template<uint N> vector<int16_t, N> asint16(vector<float16_t, N> input); template<uint N> vector<int16_t, N> asint16(vector<int16_t, N> input); template<uint N> vector<int16_t, N> asint16(vector<uint16_t, N> input);

  • Returns: A scalar or vector object of 16-bit signed integer values. Each bit in the object representation of the input argument is replicated into the newly created integer scalar or vector return value.

  • Remarks: An implementation will only provide this function if it supports native 16-bit data types.

int asint(float input); int asint(int input); int asint(uint input); template<uint N> vector<int, N> asint(vector<float, N> input); template<uint N> vector<int, N> asint(vector<int, N> input); template<uint N> vector<int, N> asint(vector<uint, N> input);

  • Returns: A scalar or vector object of 32-bit signed integer values. Each bit in the object representation of the input argument is replicated into the newly created integer scalar or vector return value.

void asuint(double input, out uint lowBits, out uint highBits); template<uint N> void asuint(vector<double, N> input, out vector<uint, N> lowBits, out vector<uint, N> highBits);

  • Returns: The scalar or vector lowBits is initialized with the 32 least significant bits of the corresponding element of the input argument replicated.

  • Returns: The scalar or vector highBits is initialized with the 32 most significant bits of the corresponding element of the input argument replicated.

uint asuint(float input); uint asuint(int input); uint asuint(uint input); template<uint N> vector<uint, N> asuint(vector<float, N> input); template<uint N> vector<uint, N> asuint(vector<int, N> input); template<uint N> vector<uint, N> asuint(vector<uint, N> input);

  • Returns: A scalar or vector object of 32-bit unsigned integer values. Each bit in the object representation of the input argument is replicated into the newly created unsigned integer scalar or vector return value.

uint16_t asuint16(float16_t input); uint16_t asuint16(int16_t input); uint16_t asuint16(uint16_t input); template<uint N> vector<uint16_t, N> asuint16(vector<float16_t, N> input); template<uint N> vector<uint16_t, N> asuint16(vector<int16_t, N> input); template<uint N> vector<uint16_t, N> asuint16(vector<uint16_t, N> input);

  • Returns: A scalar or vector object of 16-bit unsigned integer values. Each bit in the object representation of the input argument is replicated into the newly created unsigned integer scalar or vector return value.

  • Remarks: An implementation will only provide this function if it supports native 16-bit data types.

float f16tof32(uint input); template<uint N> vector<float, N> f16tof32(vector<uint, N> input);

  • Returns: A scalar or vector object of 32-bit floating-point values. The lower 16-bits of the object representation of each element of input is interpreted as a 16-bit floating-point value, and the value is precisely converted to a 32-bit floating-point value.

uint f32tof16(float input); template<uint N> vector<uint, N> f32tof16(vector<float, N> input);

  • Returns: A scalar or vector object of 32-bit unsigned integer values. Each element of the input argument is first converted to a 16-bit floating-point value with an implementation-defined rounding mode, then the bit pattern of the 16-bit value is replicated into the low bits of the corresponding output 32-bit unsigned integer.