Intrinsics1 min read

frexp

Splits a floating-point value into mantissa and exponent.

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

Test frexp in a live shader

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

Open Playground

The frexp function decomposes a float into a normalized mantissa and an integer exponent. It returns a BwslFrexpResult struct with mantissa and exponent fields.

Live Demo

Signature

bwsl
frexp :: (float x) -> BwslFrexpResult
bwsl
struct BwslFrexpResult {
mantissa: float
exponent: int
}

Parameters

ParameterTypeDescription
xfloatValue to decompose

Return Value

Returns BwslFrexpResult, where mantissa is the normalized significand and exponent is the integer power-of-two exponent.

Example

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

Compiled Output

When compiled to GLSL:

glsl
frexp(x, exponent)

See Also

  • ldexp - Recombine mantissa and exponent
  • log2 - Base-2 logarithm
  • exp2 - Base-2 exponential