Skip to content

rtm/scalard.h

#include "rtm/scalard.h"

scalar_set

scalard scalar_set(double xyzw)

Creates a scalar from a floating point value.

scalar_store

void scalar_store(double input, double* output)

Writes a scalar to memory.

scalar_cast

double scalar_cast(scalard input)

Casts a scalar into a floating point value.

scalar_floor

double scalar_floor(double 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

double scalar_ceil(double 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

double scalar_clamp(double input, double min, double max)

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

scalar_abs

double scalar_abs(double input)

Returns the absolute value of the input.

scalar_sqrt

double scalar_sqrt(double input)

Returns the square root of the input.

scalar_sqrt_reciprocal

double scalar_sqrt_reciprocal(double input)

Returns the reciprocal square root of the input.

scalar_reciprocal

constexpr double scalar_reciprocal(double input)

Returns the reciprocal of the input.

scalar_add

constexpr double scalar_add(double lhs, double rhs)

Returns the addition of the two scalar inputs.

scalar_sub

constexpr double scalar_sub(double lhs, double rhs)

Returns the subtraction of the two scalar inputs.

scalar_mul

constexpr double scalar_mul(double lhs, double rhs)

Returns the multiplication of the two scalar inputs.

scalar_div

constexpr double scalar_div(double lhs, double rhs)

Returns the division of the two scalar inputs.

scalar_mul_add

double scalar_mul_add(double s0, double s1, double s2)

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

scalar_neg_mul_sub

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

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

scalar_lerp

double scalar_lerp(double start, double end, double 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

double scalar_exp(double 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

double scalar_log(double 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

double scalar_eerp(double start, double end, double 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

double scalar_min(double left, double right)

Returns the smallest of the two inputs.

scalar_max

double scalar_max(double left, double right)

Returns the largest of the two inputs.

scalar_equal

constexpr bool scalar_equal(double lhs, double rhs)

Returns true if both inputs are equal, false otherwise.

scalar_lower_than

constexpr bool scalar_lower_than(double lhs, double rhs)

Returns true if lhs < rhs, false otherwise.

scalar_lower_equal

constexpr bool scalar_lower_equal(double lhs, double rhs)

Returns true if lhs <= rhs, false otherwise.

scalar_greater_than

constexpr bool scalar_greater_than(double lhs, double rhs)

Returns true if lhs > rhs, false otherwise.

scalar_greater_equal

constexpr bool scalar_greater_equal(double lhs, double rhs)

Returns true if lhs >= rhs, false otherwise.

scalar_near_equal

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

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

scalar_is_finite

bool scalar_is_finite(double input)

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

scalar_round_symmetric

double scalar_round_symmetric(double 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

double scalar_round_bankers(double 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

double scalar_fraction(double value)

Returns the fractional part of the input.

scalar_safe_to_double

template<typename SrcIntegralType>
double scalar_safe_to_double(SrcIntegralType input)

Safely casts an integral input into a float64 output.

scalar_load

double scalar_load(const double* input)

Loads a scalar from memory.

scalar_load_as_scalar

scalard scalar_load_as_scalar(const double* input)

Loads a scalar from memory.

Trigonometric functions

scalar_sin

double scalar_sin(double angle)

Returns the sine of the input angle.

scalar_cos

double scalar_cos(double angle)

Returns the cosine of the input angle.

scalar_sincos

vector4d scalar_sincos(double 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(double angle, double& out_sin, double& out_cos)

Returns both sine and cosine of the input angle.

scalar_asin

double scalar_asin(double value)

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

scalar_acos

double scalar_acos(double value)

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

scalar_tan

double scalar_tan(double angle)

Returns the tangent of the input angle.

scalar_atan

double scalar_atan(double 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

double scalar_atan2(double y, double 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 double scalar_deg_to_rad(double deg)

Converts degrees into radians.

scalar_rad_to_deg

constexpr double scalar_rad_to_deg(double rad)

Converts radians into degrees.