Intrinsics1 min read
asfloat
Reinterprets integer bits as floating-point values.
Reading Time
1 min
Word Count
108
Sections
7
Try It Live
Test asfloat in a live shader
Open the playground, start from a visual preset, and wire asfloat into the fragment stage to see how it behaves with real values.
Open PlaygroundThe asfloat function reinterprets the bit pattern of an integer value as a floating-point value. It does not perform numeric conversion.
Live Demo
Signature
bwsl
asfloat :: (int x) -> float
asfloat :: (uint x) -> float
asfloat :: (intN x) -> floatN
asfloat :: (uintN x) -> floatN
Parameters
| Parameter | Type | Description |
|---|---|---|
x | int, uint, or integer vector | Raw IEEE-754 bit pattern |
Return Value
Returns a float or float vector with the same bits as x.
Example
bwsl
uint oneBits = 0x3f800000u;
float one = asfloat(oneBits);Not a Numeric Cast
asfloat(1u) does not return 1.0; it returns the float represented by bit pattern 0x00000001.
Compiled Output
When compiled to GLSL:
glsl
uintBitsToFloat(x)
When compiled to HLSL:
hlsl
asfloat(x)
When compiled to Metal:
metal
as_type<float>(x)