ftz 0.0.1
Fast, reproducible floating-point arithmetic
Loading...
Searching...
No Matches
Arithmetic and math

Functions

template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::fma (basic_ftz32< Hardware > a, basic_ftz32< Hardware > b, basic_ftz32< Hardware > c) noexcept
 Computes a*b+c with one fused rounding and the FTZ boundary repair.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::sin (basic_ftz32< Hardware > a) noexcept
 Returns the reproducible sine approximation in radians; signed zero is preserved and infinity gives NaN.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::cos (basic_ftz32< Hardware > a) noexcept
 Returns the reproducible cosine approximation in radians; either zero gives one and infinity gives NaN.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::tanh (basic_ftz32< Hardware > a) noexcept
 Returns the reproducible hyperbolic tangent; signed zero is preserved and infinities give signed one.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::log (basic_ftz32< Hardware > a) noexcept
 Returns the natural-log approximation; either zero gives negative infinity, negative nonzero values give NaN.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::log1p (basic_ftz32< Hardware > a) noexcept
 Approximates log(1+x); -1 gives negative infinity, x below -1 gives NaN, and signed zero is preserved.
template<unsigned int Degree = 6, bool Hardware>
requires (Degree >= 1 && Degree <= 7)
constexpr basic_ftz32< Hardware > ftz::exp (basic_ftz32< Hardware > a) noexcept
 Returns the reproducible exponential; negative infinity gives positive zero and positive infinity is preserved.
template<bool Hardware, bool Flush, unsigned int Degree>
requires (!Flush && Degree >= 1 && Degree <= 7)
constexpr basic_ftz32< Hardware > ftz::exp (basic_ftz32< Hardware > a, std::bool_constant< Flush >, std::integral_constant< unsigned int, Degree >) noexcept
 Delegates native's degree-aware ADL call to the scalar FTZ exponential.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::expm1 (basic_ftz32< Hardware > a) noexcept
 Approximates exp(x)-1 without subtracting one for tiny x; signed zero is preserved.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::atan2 (basic_ftz32< Hardware > y, basic_ftz32< Hardware > x) noexcept
 Returns the angle in radians for (y,x), retaining signed-axis and infinity quadrants; NaN inputs give NaN.
template<bool Hardware>
constexpr std::pair< basic_ftz32< Hardware >, basic_ftz32< Hardware > > ftz::sincos (basic_ftz32< Hardware > a) noexcept
 Returns sine followed by cosine, sharing reduction; C++ uses a pair and HLSL uses named fields.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::sqrt (basic_ftz32< Hardware > a) noexcept
 Returns the reciprocal-refined square-root approximation; signed zero and positive infinity are preserved, negative nonzero values give NaN.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::floor (basic_ftz32< Hardware > a) noexcept
 Rounds toward negative infinity, independently of the ambient rounding direction; retains signed zero and infinities.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::ceil (basic_ftz32< Hardware > a) noexcept
 Rounds toward positive infinity, independently of the ambient rounding direction; retains signed zero and infinities.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::trunc (basic_ftz32< Hardware > a) noexcept
 Rounds toward zero, independently of the ambient rounding direction; retains signed zero and infinities.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::abs (basic_ftz32< Hardware > a) noexcept
 Clears the sign bit without floating-point arithmetic.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::neg (basic_ftz32< Hardware > a) noexcept
 Flips the sign bit without floating-point arithmetic.
template<bool Hardware>
constexpr bool ftz::isnan (basic_ftz32< Hardware > a) noexcept
 Tests the encoded NaN class without floating-point arithmetic or quieting a signaling NaN.
template<bool Hardware>
constexpr bool ftz::isinf (basic_ftz32< Hardware > a) noexcept
 Tests for either signed infinity by its encoded bits.
template<bool Hardware>
constexpr bool ftz::isfinite (basic_ftz32< Hardware > a) noexcept
 Tests for zero or finite magnitude by its encoded bits.
template<bool Hardware>
constexpr bool ftz::signbit (basic_ftz32< Hardware > a) noexcept
 Tests the sign bit, including negative zero and signed NaNs.
template<bool Hardware>
constexpr basic_ftz32< Hardware > ftz::copysign (basic_ftz32< Hardware > a, basic_ftz32< Hardware > b) noexcept
 Copies the second operand's sign to the first operand's magnitude, preserving the magnitude's NaN payload.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::sin (T &&a) noexcept(noexcept(sin(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Returns the reproducible sine approximation in radians; signed zero is preserved and infinity gives NaN. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::cos (T &&a) noexcept(noexcept(cos(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Returns the reproducible cosine approximation in radians; either zero gives one and infinity gives NaN. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::sincos (T &&a) noexcept(noexcept(sincos(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Returns sine followed by cosine, sharing reduction; C++ uses a pair and HLSL uses named fields. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::tanh (T &&a) noexcept(noexcept(tanh(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Returns the reproducible hyperbolic tangent; signed zero is preserved and infinities give signed one. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::log (T &&a) noexcept(noexcept(log(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Returns the natural-log approximation; either zero gives negative infinity, negative nonzero values give NaN. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::log1p (T &&a) noexcept(noexcept(log1p(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Approximates log(1+x); -1 gives negative infinity, x below -1 gives NaN, and signed zero is preserved. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<unsigned int Degree = 6, class T>
requires (detail::scalar_argument<T &&> && Degree >= 1 && Degree <= 7)
constexpr auto ftz::exp (T &&a) noexcept(noexcept(exp< Degree >(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Returns the reproducible exponential; negative infinity gives positive zero and positive infinity is preserved. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::expm1 (T &&a) noexcept(noexcept(expm1(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Approximates exp(x)-1 without subtracting one for tiny x; signed zero is preserved. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::sqrt (T &&a) noexcept(noexcept(sqrt(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Returns the reciprocal-refined square-root approximation; signed zero and positive infinity are preserved, negative nonzero values give NaN. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::floor (T &&a) noexcept(noexcept(floor(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Rounds toward negative infinity, independently of the ambient rounding direction; retains signed zero and infinities. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::ceil (T &&a) noexcept(noexcept(ceil(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Rounds toward positive infinity, independently of the ambient rounding direction; retains signed zero and infinities. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::trunc (T &&a) noexcept(noexcept(trunc(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Rounds toward zero, independently of the ambient rounding direction; retains signed zero and infinities. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::abs (T &&a) noexcept(noexcept(abs(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Clears the sign bit without floating-point arithmetic. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::neg (T &&a) noexcept(noexcept(neg(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Flips the sign bit without floating-point arithmetic. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::isnan (T &&a) noexcept(noexcept(isnan(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Tests the encoded NaN class without floating-point arithmetic or quieting a signaling NaN. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::isinf (T &&a) noexcept(noexcept(isinf(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Tests for either signed infinity by its encoded bits. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::isfinite (T &&a) noexcept(noexcept(isfinite(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Tests for zero or finite magnitude by its encoded bits. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class T>
requires detail::scalar_argument<T &&>
constexpr auto ftz::signbit (T &&a) noexcept(noexcept(signbit(detail::scalar_argument_t< T && >(std::forward< T >(a)))))
 Tests the sign bit, including negative zero and signed NaNs. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class A, class B, class C>
requires detail::scalar_arguments<A &&,B &&,C &&> && (!(ftz32_type<A> && ftz32_type<B> && ftz32_type<C>))
constexpr auto ftz::fma (A &&a, B &&b, C &&c) noexcept(noexcept(fma(detail::scalar_arguments_t< A &&, B &&, C && >(std::forward< A >(a)), detail::scalar_arguments_t< A &&, B &&, C && >(std::forward< B >(b)), detail::scalar_arguments_t< A &&, B &&, C && >(std::forward< C >(c)))))
 Computes a*b+c with one fused rounding and the FTZ boundary repair. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class A, class B>
requires detail::scalar_arguments<A &&,B &&> && (!(ftz32_type<A> && ftz32_type<B>))
constexpr auto ftz::atan2 (A &&a, B &&b) noexcept(noexcept(atan2(detail::scalar_arguments_t< A &&, B && >(std::forward< A >(a)), detail::scalar_arguments_t< A &&, B && >(std::forward< B >(b)))))
 Returns the angle in radians for (y,x), retaining signed-axis and infinity quadrants; NaN inputs give NaN. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.
template<class A, class B>
requires detail::scalar_arguments<A &&,B &&> && (!(ftz32_type<A> && ftz32_type<B>))
constexpr auto ftz::copysign (A &&a, B &&b) noexcept(noexcept(copysign(detail::scalar_arguments_t< A &&, B && >(std::forward< A >(a)), detail::scalar_arguments_t< A &&, B && >(std::forward< B >(b)))))
 Copies the second operand's sign to the first operand's magnitude, preserving the magnitude's NaN payload. Converts each forwarded argument once; the selected policy and conversion noexcept are retained.

Detailed Description

Finite arithmetic requires RNE, fused FMA and compilation without reassociation or implicit multiply/add contraction. m32 works in gradual or admitted flush mode; h32 requires admitted hardware flushing on every participating thread. Elementary division, square root and transcendental functions follow their specified approximation graphs, not a correctly-rounded libm guarantee. Use unqualified calls for ADL. Explicit std:: math or float conversion exits this contract. NaN signs/payloads are unspecified after numerical operations; classification and sign transport inspect or preserve their bits instead. The following example is instantiated for both m32 and h32 (T).

T zero(0.f), one(1.f), negative_one(-1.f);
auto fused = fma(one, T(2.f), T(1.f));
auto [sine, cosine] = sincos(zero); // std::pair<T,T>, sine first.
auto minus_infinity = log(zero);
auto pole = log1p(negative_one);
auto invalid = sqrt(negative_one);
auto down = floor(T(-.25f));
auto toward_zero = trunc(T(-.25f)); // Preserves negative zero.

Function Documentation

◆ abs()

template<bool Hardware>
basic_ftz32< Hardware > ftz::abs ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Clears the sign bit without floating-point arithmetic.

Returns
A value with the input FTZ policy.

Definition at line 393 of file ftz.ccm.

◆ atan2()

template<bool Hardware>
basic_ftz32< Hardware > ftz::atan2 ( basic_ftz32< Hardware > y,
basic_ftz32< Hardware > x )
inlinenodiscardconstexprexportnoexcept

Returns the angle in radians for (y,x), retaining signed-axis and infinity quadrants; NaN inputs give NaN.

Returns
A value with the input FTZ policy.

Definition at line 335 of file ftz.ccm.

◆ ceil()

template<bool Hardware>
basic_ftz32< Hardware > ftz::ceil ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Rounds toward positive infinity, independently of the ambient rounding direction; retains signed zero and infinities.

Returns
A value with the input FTZ policy.

Definition at line 368 of file ftz.ccm.

◆ copysign()

template<bool Hardware>
basic_ftz32< Hardware > ftz::copysign ( basic_ftz32< Hardware > a,
basic_ftz32< Hardware > b )
inlinenodiscardconstexprexportnoexcept

Copies the second operand's sign to the first operand's magnitude, preserving the magnitude's NaN payload.

Returns
A value with the input FTZ policy.

Definition at line 424 of file ftz.ccm.

◆ cos()

template<bool Hardware>
basic_ftz32< Hardware > ftz::cos ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Returns the reproducible cosine approximation in radians; either zero gives one and infinity gives NaN.

Returns
A value with the input FTZ policy.

Definition at line 293 of file ftz.ccm.

◆ exp() [1/2]

template<unsigned int Degree = 6, bool Hardware>
requires (Degree >= 1 && Degree <= 7)
basic_ftz32< Hardware > ftz::exp ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Returns the reproducible exponential; negative infinity gives positive zero and positive infinity is preserved.

Returns
A value with the input FTZ policy.
Template Parameters
DegreePolynomial degree in [1,7]; the default is 6.

Definition at line 318 of file ftz.ccm.

◆ exp() [2/2]

template<bool Hardware, bool Flush, unsigned int Degree>
requires (!Flush && Degree >= 1 && Degree <= 7)
basic_ftz32< Hardware > ftz::exp ( basic_ftz32< Hardware > a,
std::bool_constant< Flush > ,
std::integral_constant< unsigned int, Degree >  )
inlinenodiscardconstexprexportnoexcept

Delegates native's degree-aware ADL call to the scalar FTZ exponential.

Template Parameters
FlushMust be false; the input type determines the FTZ policy.
DegreePolynomial degree in [1,7].

Definition at line 324 of file ftz.ccm.

◆ expm1()

template<bool Hardware>
basic_ftz32< Hardware > ftz::expm1 ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Approximates exp(x)-1 without subtracting one for tiny x; signed zero is preserved.

Returns
A value with the input FTZ policy.

Definition at line 329 of file ftz.ccm.

◆ floor()

template<bool Hardware>
basic_ftz32< Hardware > ftz::floor ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Rounds toward negative infinity, independently of the ambient rounding direction; retains signed zero and infinities.

Returns
A value with the input FTZ policy.

Definition at line 355 of file ftz.ccm.

◆ fma()

template<bool Hardware>
basic_ftz32< Hardware > ftz::fma ( basic_ftz32< Hardware > a,
basic_ftz32< Hardware > b,
basic_ftz32< Hardware > c )
inlinenodiscardconstexprexportnoexcept

Computes a*b+c with one fused rounding and the FTZ boundary repair.

Returns
A value with the input FTZ policy.

Definition at line 279 of file ftz.ccm.

◆ isfinite()

template<bool Hardware>
bool ftz::isfinite ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Tests for zero or finite magnitude by its encoded bits.

Returns
A scalar bool.

Definition at line 413 of file ftz.ccm.

◆ isinf()

template<bool Hardware>
bool ftz::isinf ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Tests for either signed infinity by its encoded bits.

Returns
A scalar bool.

Definition at line 408 of file ftz.ccm.

◆ isnan()

template<bool Hardware>
bool ftz::isnan ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Tests the encoded NaN class without floating-point arithmetic or quieting a signaling NaN.

Returns
A scalar bool.

Definition at line 403 of file ftz.ccm.

◆ log()

template<bool Hardware>
basic_ftz32< Hardware > ftz::log ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Returns the natural-log approximation; either zero gives negative infinity, negative nonzero values give NaN.

Returns
A value with the input FTZ policy.

Definition at line 305 of file ftz.ccm.

◆ log1p()

template<bool Hardware>
basic_ftz32< Hardware > ftz::log1p ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Approximates log(1+x); -1 gives negative infinity, x below -1 gives NaN, and signed zero is preserved.

Returns
A value with the input FTZ policy.

Definition at line 311 of file ftz.ccm.

◆ neg()

template<bool Hardware>
basic_ftz32< Hardware > ftz::neg ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Flips the sign bit without floating-point arithmetic.

Returns
A value with the input FTZ policy.

Definition at line 398 of file ftz.ccm.

◆ signbit()

template<bool Hardware>
bool ftz::signbit ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Tests the sign bit, including negative zero and signed NaNs.

Returns
A scalar bool.

Definition at line 418 of file ftz.ccm.

◆ sin()

template<bool Hardware>
basic_ftz32< Hardware > ftz::sin ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Returns the reproducible sine approximation in radians; signed zero is preserved and infinity gives NaN.

Returns
A value with the input FTZ policy.

Definition at line 287 of file ftz.ccm.

◆ sincos()

template<bool Hardware>
std::pair< basic_ftz32< Hardware >, basic_ftz32< Hardware > > ftz::sincos ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Returns sine followed by cosine, sharing reduction; C++ uses a pair and HLSL uses named fields.

Returns
std::pair<basic_ftz32<Hardware>,basic_ftz32<Hardware>>.

Definition at line 341 of file ftz.ccm.

◆ sqrt()

template<bool Hardware>
basic_ftz32< Hardware > ftz::sqrt ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Returns the reciprocal-refined square-root approximation; signed zero and positive infinity are preserved, negative nonzero values give NaN.

Returns
A value with the input FTZ policy.

Definition at line 349 of file ftz.ccm.

◆ tanh()

template<bool Hardware>
basic_ftz32< Hardware > ftz::tanh ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Returns the reproducible hyperbolic tangent; signed zero is preserved and infinities give signed one.

Returns
A value with the input FTZ policy.

Definition at line 299 of file ftz.ccm.

◆ trunc()

template<bool Hardware>
basic_ftz32< Hardware > ftz::trunc ( basic_ftz32< Hardware > a)
inlinenodiscardconstexprexportnoexcept

Rounds toward zero, independently of the ambient rounding direction; retains signed zero and infinities.

Returns
A value with the input FTZ policy.

Definition at line 381 of file ftz.ccm.