GLSL built-in function

floatBitsToInt()

Reinterprets floating-point bits as a signed integer.

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

Syntax

genIType floatBitsToInt(genType x)

genType means float / vec2 / vec3 / vec4; genIType means int / ivec2 / ivec3 / ivec4; matching placeholders use the same type.

Parameters

x
Input value or left-hand vector

Return value

A signed integer or signed integer vector carrying the floating-point input's bit pattern, not its numeric conversion.

Live example

Edit the code and the preview updates as you type.

What floatBitsToInt does

Reinterprets floating-point bits as a signed integer.

Read the preview

The comparison floatBitsToInt(1.0)==1065353216 is true everywhere, so the background is uniform. Change only 1.0 to 2.0 and the unchanged integer comparison becomes false.

Core call

float(floatBitsToInt(1.0)==1065353216);

This is not numeric int(x) conversion; the example checks the bit pattern of 1.0.

Experiment

Replace the comparison integer 1065353216 with 1073741824 and the input with 2.0. The true color returns because the new integer matches the bit pattern of 2.0.

Specification

GLSL ES 3.00 built-in functions, chapter 8

Related functions