Intrinsics1 min read

ldexp

Multiplies a floating-point value by a power of two.

Reading Time
1 min
Word Count
97
Sections
7
Try It Live

Test ldexp in a live shader

Open the playground, start from a visual preset, and wire ldexp into the fragment stage to see how it behaves with real values.

Open Playground

The ldexp function returns x * 2^e, applying an integer exponent directly to a floating-point significand. It is useful with frexp, custom encodings, and scale factors that are naturally powers of two.

Live Demo

Signature

bwsl
ldexp :: (float x, int e) -> float

Parameters

ParameterTypeDescription
xfloatFloating-point value to scale
eintPower-of-two exponent

Return Value

Returns x * exp2(float(e)).

Example

bwsl
BwslFrexpResult parts = frexp(value);
float reconstructed = ldexp(parts.mantissa, parts.exponent);

Compiled Output

When compiled to SPIR-V:

spirv
GLSL.std.450 Ldexp

When compiled to GLSL ES:

glsl
x * exp2(float(e))

See Also

  • frexp - Split a float into mantissa and exponent
  • exp2 - Base-2 exponential
  • rcp - Reciprocal