i2f 0x86

Converts the int on top of the stack to float.

Opcode
0x86 (134)
Family
Conversions
Operands
none
Length
1 byte
Operand stack
…, value (int) → …, result (float)
Can throw
nothing at run time (beyond linking errors)

What it does

Converts the int on top of the stack to float.

A widening conversion: javac emits it wherever Java converts implicitly, such as assigning an int to a long or passing an int where a double is expected. It can lose precision: not every int has an exact float.

How often javac uses it

In JDK 25.0.5's java.base module, i2f appears 65 times in 28 of its 7,391 classes: <0.01% of all instructions, the 163rd most common of 194 opcodes in use. Some of the methods that use it: java.io.ObjectOutputStream$HandleTable.<init>, java.lang.Byte.floatValue, java.lang.Float.float16ToFloat, java.lang.Integer.floatValue.

Example

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; i2f is highlighted.

static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25
… 29 instructions before
47double fd = f;
40dstore 17// fd
48long fl = (long) f;
42fload_3 // f
43f2l
44lstore 19// fl
49float iff = i;
46iload_0 // i
47i2f
48fstore 21// iff
50double id = i;
50iload_0 // i
51i2d
52dstore 22// id
51double ld = l;
54lload_1 // l
55l2d
… 43 instructions after

Open in the viewer

Related instructions

i2l Converts the int on top of the stack to long.i2d Converts the int on top of the stack to double.l2f Converts the long on top of the stack to float.

Specification: JVMS §6.5, i2f (Java SE 25).