interface IFloat
Inherits from: IArithmetic, IDifferentiable
Description
Represents a type that can be used for floating point arithmetic operations.
Implemented by builtin scalar types: float, half, double.
Also implemented by vector<T, N> where T is one of the above scalar types.
Methods
Remarks
This interface can be used to define generic functions that work with floating-point-like types. See example below.
Example
The following code defines a generic function that computes a*b+1, where a, b can be any floating point scalar or vector types.
T compute<T:IFloat>(T a, T b)
{
return a * b + T(1.0f);
}
RWStructuredBuffer<float> outputBuffer;
[numthreads(1,1,1)]
void test()
{
float a = 2.0;
float b = 3.0;
outputBuffer[0] = compute(a, b); // result = 2.0*3.0 + 1.0 = 7.0
half2 a2 = half2(2.0h, 3.0h);
half2 b2 = half2(4.0h, 5.0h);
// result2 = half2(2*4 + 1, 3*5 + 1) = half2(9, 16)
half2 result2 = compute(a2, b2);
outputBuffer[1] = result2.x;
}