isinf
Componentwise test for IEEE-754 +/-infinity values.
Test isinf in a live shader
Open the playground, start from a visual preset, and wire isinf into the fragment stage to see how it behaves with real values.
Open PlaygroundLive Demo Pending
The isinf function returns true for each component that is +infinity or -infinity. Scalar input produces a bool; vector input produces a bvecN of the same width.
Signature
isinf :: (float x) -> bool
isinf :: (float2 x) -> bool2
isinf :: (float3 x) -> bool3
isinf :: (float4 x) -> bool4
Parameters
| Parameter | Type | Description |
|---|---|---|
x | float, float2, float3, float4 | Value(s) to classify |
Return Value
Returns a bool (or bvecN) where each component is true iff the corresponding input is +infinity or -infinity. Finite values (including denormals and NaN) return false. Use isnan to detect NaN.
Example
pipeline ClampRuntime {
fragment {
float lum = dot(input.color.rgb, float3(0.2126, 0.7152, 0.0722));
float gain = exp(input.exposure); // may overflow to +inf
float scaled = lum * gain;
if (isinf(scaled)) {
scaled = 1e30; // cap before tone-mapping
}
output.color = float4(float3(scaled), 1.0);
}
}Common Use Cases
Guarding Against Division Overflow
// 1/x can overflow to inf when x is a denormal.
float recip = 1.0 / x;
float safe = isinf(recip) ? 3.4e38 : recip; // cap at ~FLOAT_MAX
Componentwise Plus any
// Any channel overflowed?
bool3 overflowed = isinf(color.rgb);
if (any(overflowed)) {
output.color = float4(1.0, 0.5, 0.0, 1.0);
return;
}
Distinguishing +inf From -inf
// isinf alone doesn't give you the sign.
if (isinf(v)) {
float signBit = sign(v); // +1.0 or -1.0
// handle positive and negative overflow separately
}
Fast-Math May Elide
As with isnan, some backends' aggressive fast-math modes can legally assume no infinities. BWSL emits the IEEE-correct opcode, but downstream toolchains that re-optimize the generated HLSL / GLSL may collapse isinf(x) to false.
Infinities Come From Division and Overflow
Common producers: 1.0 / 0.0, exp(large), pow(large, large), 1e30 * 1e30. isinf is usually the right guard just before a final divide or tone-map step — catch garbage before it propagates to a render target.
Compiled Output
When compiled to GLSL:
isinf(x)
When compiled to HLSL:
isinf(x)
When compiled to Metal:
isinf(x)
When compiled to SPIR-V:
Uses the OpIsInf instruction directly. The result type's component count matches the input.