ftz 0.0.1
Fast, reproducible floating-point arithmetic
Loading...
Searching...
No Matches
ftz.ccm File Reference
module ftz

Reproducible float arithmetic with manual or hardware flush-to-zero. More...

#include <native/attributes.h>
#include <ftz/config.h>
#include <algorithm>
#include <array>
#include <bit>
#include <cmath>
#include <concepts>
#include <cstdint>
#include <cstring>
#include <type_traits>
#include <utility>
#include <ftz/ftz32_ops.h>
#include "ftz/simd.h"
import ftz.controls;
import native.scalar;
import native.math;

Go to the source code of this file.

Classes

struct  ftz::basic_ftz32< Hardware >
 Binary32 value with a compile-time signed-FTZ policy. More...

Concepts

concept  ftz::ftz32_type
 Accepts either scalar policy after removing cv/ref qualifiers.
concept  ftz::ftz32_scalar
 Accepts built-in arithmetic operands for conversion into a chosen FTZ policy.

Typedefs

using ftz::m32 = basic_ftz32<false>
 Explicit-normalization value; arithmetic supports gradual and admitted flush regions.
using ftz::h32 = basic_ftz32<true>
 Hardware-normalization value; arithmetic requires a qualified flush region.
using ftz::ftz32 = basic_ftz32<FTZ_FP32_HARDWARE_FTZ != 0>
 Compatibility alias selected by the installed FTZ_FP32_HARDWARE_FTZ package setting. Both m32 and h32 remain available; do not override this package setting per translation unit.

Functions

template<bool Hardware, ftz32_scalar T>
constexpr basic_ftz32< Hardware > ftz::operator+ (basic_ftz32< Hardware > a, T b) noexcept
 Applies the FTZ arithmetic/sign operation, preserving this policy and signed-zero semantics.
template<bool Hardware, ftz32_scalar T>
constexpr basic_ftz32< Hardware > ftz::operator+ (T a, basic_ftz32< Hardware > b) noexcept
 Applies the FTZ arithmetic/sign operation, preserving this policy and signed-zero semantics.
template<bool Hardware, ftz32_scalar T>
constexpr basic_ftz32< Hardware > ftz::operator- (basic_ftz32< Hardware > a, T b) noexcept
 Applies the FTZ arithmetic/sign operation, preserving this policy and signed-zero semantics.
template<bool Hardware, ftz32_scalar T>
constexpr basic_ftz32< Hardware > ftz::operator- (T a, basic_ftz32< Hardware > b) noexcept
 Applies the FTZ arithmetic/sign operation, preserving this policy and signed-zero semantics.
template<bool Hardware, ftz32_scalar T>
constexpr basic_ftz32< Hardware > ftz::operator* (basic_ftz32< Hardware > a, T b) noexcept
 Applies the FTZ arithmetic/sign operation, preserving this policy and signed-zero semantics.
template<bool Hardware, ftz32_scalar T>
constexpr basic_ftz32< Hardware > ftz::operator* (T a, basic_ftz32< Hardware > b) noexcept
 Applies the FTZ arithmetic/sign operation, preserving this policy and signed-zero semantics.
template<bool Hardware, ftz32_scalar T>
constexpr basic_ftz32< Hardware > ftz::operator/ (basic_ftz32< Hardware > a, T b) noexcept
 Divides using the reproducible reciprocal-refinement graph, with signed IEEE-like zero/infinity cases.
template<bool Hardware, ftz32_scalar T>
constexpr basic_ftz32< Hardware > ftz::operator/ (T a, basic_ftz32< Hardware > b) noexcept
 Divides using the reproducible reciprocal-refinement graph, with signed IEEE-like zero/infinity cases.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator== (basic_ftz32< Hardware > a, T b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator== (T a, basic_ftz32< Hardware > b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator!= (basic_ftz32< Hardware > a, T b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator!= (T a, basic_ftz32< Hardware > b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator< (basic_ftz32< Hardware > a, T b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator< (T a, basic_ftz32< Hardware > b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator> (basic_ftz32< Hardware > a, T b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator> (T a, basic_ftz32< Hardware > b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator<= (basic_ftz32< Hardware > a, T b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator<= (T a, basic_ftz32< Hardware > b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator>= (basic_ftz32< Hardware > a, T b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
template<bool Hardware, ftz32_scalar T>
constexpr bool ftz::operator>= (T a, basic_ftz32< Hardware > b) noexcept
 Compares values; NaN is unordered (only != is true), and the two zero signs compare equal.
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.
template<ftz32_type T = ftz32>
ftz32_cpu_admission ftz::probe_ftz32_cpu ()
 Observes whether this compiled scalar profile meets the requested policy.

Variables

template<class T>
constexpr bool ftz::is_ftz32 = false
 Identifies the two unqualified FTZ scalar types. Use ftz32_type to ignore cv/ref.

Detailed Description

Reproducible float arithmetic with manual or hardware flush-to-zero.

Exports the scalar policies, their SIMD customizations and math functions. Admission checks verify rounding, fused arithmetic, signed flushing and boundary repair before a thread uses the hardware policy.

Definition in file ftz.ccm.