3#include "ftz/ftz32_ops.h"
27 result.bits_ = detail::ftz32_canonical(bits);
38 result.bits_ = asuint(value);
54 result.bits_ = detail::ftz32_add(bits_, rhs.bits_);
61 result.bits_ = detail::ftz32_add(bits_, detail::ftz32_canonical(asuint(rhs)));
68 result.bits_ = detail::ftz32_sub(bits_, rhs.bits_);
75 result.bits_ = detail::ftz32_sub(bits_, detail::ftz32_canonical(asuint(rhs)));
82 result.bits_ = detail::ftz32_mul(bits_, rhs.bits_);
89 result.bits_ = detail::ftz32_mul(bits_, detail::ftz32_canonical(asuint(rhs)));
96 result.bits_ = detail::ftz32_div(bits_, rhs.bits_);
103 result.bits_ = detail::ftz32_div(bits_, detail::ftz32_canonical(asuint(rhs)));
115 bool operator<=(
ftz32 rhs) {
return detail::ftz32_less(bits_, rhs.bits_) || detail::ftz32_equal(bits_, rhs.bits_); }
117 bool operator>=(
ftz32 rhs) {
return detail::ftz32_less(rhs.bits_, bits_) || detail::ftz32_equal(bits_, rhs.bits_); }
120 unsigned int word = detail::ftz32_canonical(asuint(rhs));
121 return detail::ftz32_less(bits_, word);
125 unsigned int word = detail::ftz32_canonical(asuint(rhs));
126 return detail::ftz32_less(word, bits_);
130 unsigned int word = detail::ftz32_canonical(asuint(rhs));
131 return detail::ftz32_equal(bits_, word);
135 unsigned int word = detail::ftz32_canonical(asuint(rhs));
136 return !detail::ftz32_equal(bits_, word);
140 unsigned int word = detail::ftz32_canonical(asuint(rhs));
141 return detail::ftz32_less(bits_, word) || detail::ftz32_equal(bits_, word);
145 unsigned int word = detail::ftz32_canonical(asuint(rhs));
146 return detail::ftz32_less(word, bits_) || detail::ftz32_equal(bits_, word);
156 result.bits_ = detail::ftz32_neg(value.bits_);
163 result.bits_ = detail::ftz32_abs(value.bits_);
171 result.bits_ = detail::ftz32_sqrt(value.bits_);
198 result.bits_ = detail::ftz32_sin(value.bits_);
206 result.bits_ = detail::ftz32_cos(value.bits_);
213 template <
unsigned int Degree = 6>
216 result.bits_ = detail::ftz32_exp<Degree>(value.bits_);
223 result.bits_ = detail::ftz32_expm1(value.bits_);
231 result.bits_ = detail::ftz32_tanh(value.bits_);
239 result.bits_ = detail::ftz32_log(value.bits_);
247 result.bits_ = detail::ftz32_log1p(value.bits_);
255 result.bits_ = detail::ftz32_atan2(y.bits_, x.bits_);
265 detail::ftz32_sincos_bits words = detail::ftz32_sincos(value.bits_);
267 result.sine.bits_ = words.sine;
268 result.cosine.bits_ = words.cosine;
273 bool isnan(
ftz32 value) {
return detail::ftz32_isnan(value.bits_); }
276 bool isinf(
ftz32 value) {
return (value.bits_ & 0x7fffffffu) == detail::ftz32_infinity; }
279 bool isfinite(
ftz32 value) {
return (value.bits_ & 0x7fffffffu) < detail::ftz32_infinity; }
282 bool signbit(
ftz32 value) {
return (value.bits_ & detail::ftz32_sign) != 0u; }
287 return ftz32::from_bits((value.bits_ & 0x7fffffffu) | (sign.bits_ & detail::ftz32_sign));
293 result.bits_ = detail::ftz32_fma(a.bits_, b.bits_, c.bits_);
307 * \brief HLSL 2021 FTZ value type, conversion factories, operators, and math overloads.
bool isinf(ftz32 value)
Tests for either signed infinity by its encoded bits.
ftz32 expm1(ftz32 value)
Approximates exp(x)-1 without subtracting one for tiny x; signed zero is preserved.
ftz32 fma(ftz32 a, ftz32 b, ftz32 c)
Computes a*b+c with one fused rounding and the FTZ boundary repair.
static ftz32 from_float(float value)
Imports a float through its bits and normalizes subnormals.
ftz32_sincos_result sincos(ftz32 value)
Returns sine followed by cosine, sharing reduction; C++ uses a pair and HLSL uses named fields.
bool signbit(ftz32 value)
Tests the sign bit, including negative zero and signed NaNs.
bool isnan(ftz32 value)
Tests the encoded NaN class without floating-point arithmetic or quieting a signaling NaN.
ftz32 cos(ftz32 value)
Returns the reproducible cosine approximation in radians; either zero gives one and infinity gives Na...
ftz32 ceil(ftz32 value)
Rounds toward positive infinity, independently of the ambient rounding direction; retains signed zero...
ftz32 log1p(ftz32 value)
Approximates log(1+x); -1 gives negative infinity, x below -1 gives NaN, and signed zero is preserved...
ftz32 sqrt(ftz32 value)
Returns the reciprocal-refined square-root approximation; signed zero and positive infinity are prese...
ftz32 abs(ftz32 value)
Clears the sign bit without floating-point arithmetic.
ftz32 atan2(ftz32 y, ftz32 x)
Returns the angle in radians for (y,x), retaining signed-axis and infinity quadrants; NaN inputs give...
float to_float()
Exports stored bits as an ordinary HLSL float, leaving this value contract.
ftz32 log(ftz32 value)
Returns the natural-log approximation; either zero gives negative infinity, negative nonzero values g...
ftz32 trunc(ftz32 value)
Rounds toward zero, independently of the ambient rounding direction; retains signed zero and infiniti...
static ftz32 zero()
Returns positive zero.
ftz32 tanh(ftz32 value)
Returns the reproducible hyperbolic tangent; signed zero is preserved and infinities give signed one.
ftz32 sin(ftz32 value)
Returns the reproducible sine approximation in radians; signed zero is preserved and infinity gives N...
static ftz32 from_bits(unsigned int bits)
Imports a binary32 word and replaces a subnormal magnitude with signed zero.
ftz32 floor(ftz32 value)
Rounds toward negative infinity, independently of the ambient rounding direction; retains signed zero...
static ftz32 unsafe_from_float32(float value)
Wraps bits unchanged; the caller must supply normal, signed zero, infinity or NaN.
ftz32 neg(ftz32 value)
Flips the sign bit without floating-point arithmetic.
ftz32 copysign(ftz32 value, ftz32 sign)
Copies the second operand's sign to the first operand's magnitude, preserving the magnitude's NaN pay...
ftz32 exp(ftz32 value)
Returns the reproducible exponential; negative infinity gives positive zero and positive infinity is ...
bool isfinite(ftz32 value)
Tests for zero or finite magnitude by its encoded bits.
unsigned int to_bits()
Exports the exact stored word without arithmetic.
Paired HLSL trig values; sine precedes cosine.
Canonical binary32 word wrapper with named HLSL imports and exports. Ordinary aggregate casts/default...
ftz32 operator/(ftz32 rhs)
Uses the selected shader FTZ policy for canonical operands.
ftz32 operator+(ftz32 rhs)
Uses the selected shader FTZ policy for canonical operands.
bool operator==(float rhs)
Imports a raw float operand before the operation.
bool operator>=(float rhs)
Imports a raw float operand before the operation.
bool operator<=(float rhs)
Imports a raw float operand before the operation.
bool operator>(ftz32 rhs)
Compares canonical values; NaN is unordered and the two zero signs compare equal.
bool operator==(ftz32 rhs)
Compares canonical values; NaN is unordered and the two zero signs compare equal.
bool operator!=(ftz32 rhs)
Compares canonical values; NaN is unordered and the two zero signs compare equal.
bool operator<(float rhs)
Imports a raw float operand before the operation.
ftz32 operator-(ftz32 rhs)
Uses the selected shader FTZ policy for canonical operands.
bool operator>(float rhs)
Imports a raw float operand before the operation.
ftz32 operator*(float rhs)
Imports a raw float operand before the operation.
ftz32 operator+(float rhs)
Imports a raw float operand before the operation.
bool operator>=(ftz32 rhs)
Compares canonical values; NaN is unordered and the two zero signs compare equal.
ftz32 operator/(float rhs)
Imports a raw float operand before the operation.
bool operator<(ftz32 rhs)
Compares canonical values; NaN is unordered and the two zero signs compare equal.
ftz32 operator-(float rhs)
Imports a raw float operand before the operation.
bool operator<=(ftz32 rhs)
Compares canonical values; NaN is unordered and the two zero signs compare equal.
bool operator!=(float rhs)
Imports a raw float operand before the operation.
ftz32 operator*(ftz32 rhs)
Uses the selected shader FTZ policy for canonical operands.