Intrinsics2 min read

isinf

Componentwise test for IEEE-754 +/-infinity values.

Reading Time
2 min
Word Count
210
Sections
10
Try It Live

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 Playground

Live Demo Pending

This intrinsic does not yet have a self-contained interactive preview. Compute-only and external-resource intrinsics need a different demo path than the current fragment and 3D showcases.

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

bwsl
isinf :: (float x) -> bool
isinf :: (float2 x) -> bool2
isinf :: (float3 x) -> bool3
isinf :: (float4 x) -> bool4

Parameters

ParameterTypeDescription
xfloat, float2, float3, float4Value(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

bwsl
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

bwsl
// 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

bwsl
// 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

bwsl
// 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:

glsl
isinf(x)

When compiled to HLSL:

hlsl
isinf(x)

When compiled to Metal:

msl
isinf(x)

When compiled to SPIR-V:

Uses the OpIsInf instruction directly. The result type's component count matches the input.

See Also

  • isnan - Componentwise test for NaN
  • sign - Distinguish positive from negative infinity
  • clamp - Cap a value at a finite range