GLSL built-in function

floatBitsToUint()

Reinterprets floating-point bits as an unsigned integer.

Demo version: GLSL ES 3.00 / WebGL 2Demo stage: Fragment

Syntax

genUType floatBitsToUint(genType x)

genType means float / vec2 / vec3 / vec4; genUType means uint / uvec2 / uvec3 / uvec4; matching placeholders use the same type.

Parameters

x
Input value or left-hand vector

Return value

An unsigned integer value for each component containing the input float's bit pattern.

Live example

Edit the code and the preview updates as you type.

What floatBitsToUint does

Reinterprets floating-point bits as an unsigned integer.

Read the preview

floatBitsToUint(1.0)==1065353216u checks the encoding of 1.0 rather than its numeric value. Comparing with 1u instead makes the result false and changes the background color.

Core call

float(floatBitsToUint(1.0)==1065353216u);

Use highp float input for bit reinterpretation; this is not truncation.

Experiment

Use floatBitsToUint(-1.0)==3212836864u in the result expression. The unsigned integer includes the sign bit, and the uniform true color confirms that encoding.

Specification

GLSL ES 3.00 built-in functions, chapter 8

Related functions