Skip to content

rtm/scalarf.h

#include "rtm/scalarf.h"

scalar_set

scalarf scalar_set(float xyzw)

Creates a scalar from a floating point value.

scalar_store

void scalar_store(float input, float* output)

Writes a scalar to memory.

scalar_cast

float scalar_cast(scalarf input)

Casts a scalar into a floating point value.

scalar_floor

float scalar_floor(float input)

Returns the largest integer value not greater than the input (round towards negative infinity). scalar_floor(1.8) = 1.0 scalar_floor(-1.8) = -2.0

scalar_ceil

float scalar_ceil(float input)

Returns the smallest integer value not less than the input (round towards positive infinity). scalar_ceil(1.8) = 2.0 scalar_ceil(-1.8) = -1.0

scalar_clamp

float scalar_clamp(float input, float min, float max)

Returns the input if it is within the min/max values otherwise the exceeded boundary is returned.

scalar_abs

float scalar_abs(float input)

Returns the absolute value of the input.

scalar_sqrt

float scalar_sqrt(float input)

Returns the square root of the input.

scalar_sqrt_reciprocal

float scalar_sqrt_reciprocal(float input)

Returns the reciprocal square root of the input.

scalar_reciprocal

float scalar_reciprocal(float input)

Returns the reciprocal of the input.

scalar_add

constexpr float scalar_add(float lhs, float rhs)

Returns the addition of the two scalar inputs.

scalar_sub

constexpr float scalar_sub(float lhs, float rhs)

Returns the subtraction of the two scalar inputs.

scalar_mul

constexpr float scalar_mul(float lhs, float rhs)

Returns the multiplication of the two scalar inputs.

scalar_div

constexpr float scalar_div(float lhs, float rhs)

Returns the division of the two scalar inputs.

scalar_mul_add

float scalar_mul_add(float s0, float s1, float s2)

Returns the multiplication/addition of the three inputs: s2 + (s0 * s1).

scalar_neg_mul_sub

constexpr float scalar_neg_mul_sub(float s0, float s1, float s2)

Returns the negative multiplication/subtraction of the three inputs: -((s0 * s1) - s2) This is mathematically equivalent to: s2 - (s0 * s1)

scalar_lerp

float scalar_lerp(float start, float end, float alpha)

Returns the linear interpolation of the two inputs at the specified alpha. The formula used is: ((1.0 - alpha) * start) + (alpha * end). Interpolation is stable and will return 'start' when alpha is 0.0 and 'end' when it is 1.0. This is the same instruction count when FMA is present but it might be slightly slower due to the extra multiplication compared to: start + (alpha * (end - start)).

scalar_exp

float scalar_exp(float input)

Returns the natural exponential of the input: e^input. The function uses the same algorithm as vector_exp(..): for the same input, the results are equal.

scalar_log

float scalar_log(float input)

Returns the natural logarithm of the input. The function uses the same algorithm as vector_log(..): for the same input, the results are equal. The result is -inf when the input is zero, and NaN when the input is negative.

scalar_eerp

float scalar_eerp(float start, float end, float alpha)

Returns the exponential interpolation of the two inputs at the specified alpha. The formula used is: start * (end / start)^alpha. For equal steps of alpha, the result changes by the same ratio. Use it to interpolate a scale. The result is 'start' when alpha is 0.0. It is approximately 'end' when alpha is 1.0. The two inputs must have the same sign and must not be zero. Otherwise, the result is undefined.

scalar_min

float scalar_min(float left, float right)

Returns the smallest of the two inputs.

scalar_max

float scalar_max(float left, float right)

Returns the largest of the two inputs.

scalar_equal

constexpr bool scalar_equal(float lhs, float rhs)

Returns true if both inputs are equal, false otherwise.

scalar_lower_than

constexpr bool scalar_lower_than(float lhs, float rhs)

Returns true if lhs < rhs, false otherwise.

scalar_lower_equal

constexpr bool scalar_lower_equal(float lhs, float rhs)

Returns true if lhs <= rhs, false otherwise.

scalar_greater_than

constexpr bool scalar_greater_than(float lhs, float rhs)

Returns true if lhs > rhs, false otherwise.

scalar_greater_equal

constexpr bool scalar_greater_equal(float lhs, float rhs)

Returns true if lhs >= rhs, false otherwise.

scalar_near_equal

bool scalar_near_equal(float lhs, float rhs, float threshold)

Returns true if both inputs are nearly equal, otherwise false: abs(lhs - rhs) <= threshold.

scalar_is_finite

bool scalar_is_finite(float input)

Returns true if the input is finite (not NaN or Inf), false otherwise.

scalar_round_symmetric

float scalar_round_symmetric(float input)

Returns the rounded input using a symmetric algorithm. scalar_round_symmetric(1.5) = 2.0 scalar_round_symmetric(1.2) = 1.0 scalar_round_symmetric(-1.5) = -2.0 scalar_round_symmetric(-1.2) = -1.0

scalar_round_bankers

float scalar_round_bankers(float input)

Returns the rounded input using banker's rounding (half to even). scalar_round_bankers(2.5) = 2.0 scalar_round_bankers(1.5) = 2.0 scalar_round_bankers(1.2) = 1.0 scalar_round_bankers(-2.5) = -2.0 scalar_round_bankers(-1.5) = -2.0 scalar_round_bankers(-1.2) = -1.0

scalar_fraction

float scalar_fraction(float value)

Returns the fractional part of the input.

scalar_safe_to_float

template<typename SrcIntegralType>
float scalar_safe_to_float(SrcIntegralType input)

Safely casts an integral input into a float32 output.

scalar_load

float scalar_load(const float* input)

Loads a scalar from memory.

scalar_load_as_scalar

scalarf scalar_load_as_scalar(const float* input)

Loads a scalar from memory.

Trigonometric functions

scalar_sin

float scalar_sin(float angle)

Returns the sine of the input angle.

scalar_cos

float scalar_cos(float angle)

Returns the cosine of the input angle.

scalar_sincos

vector4f scalar_sincos(float angle)

Returns both sine and cosine of the input angle. The result's [x] component contains sin(angle). The result's [y] component contains cos(angle). [zw] are undefined.

void scalar_sincos(float angle, float& out_sin, float& out_cos)

Returns both sine and cosine of the input angle.

scalar_asin

float scalar_asin(float value)

Returns the arc-sine of the input. Input value must be in the range [-1.0, 1.0].

scalar_acos

float scalar_acos(float value)

Returns the arc-cosine of the input. Input value must be in the range [-1.0, 1.0].

scalar_tan

float scalar_tan(float angle)

Returns the tangent of the input angle.

scalar_atan

float scalar_atan(float value)

Returns the arc-tangent of the input. Note that due to the sign ambiguity, atan cannot determine which quadrant the value resides in. See scalar_atan2.

scalar_atan2

float scalar_atan2(float y, float x)

Returns the arc-tangent of [y/x] using the sign of the arguments to determine the correct quadrant. Y represents the proportion of the y-coordinate. X represents the proportion of the x-coordinate.

scalar_deg_to_rad

constexpr float scalar_deg_to_rad(float deg)

Converts degrees into radians.

scalar_rad_to_deg

constexpr float scalar_rad_to_deg(float rad)

Converts radians into degrees.