f2i 0x8b

Converts the float on top of the stack to int.

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

What it does

Converts the float on top of the stack to int.

Rounds toward zero. NaN becomes 0, and values out of range become the int's minimum or maximum: the conversion saturates instead of wrapping.

How often javac uses it

In JDK 25.0.5's java.base module, f2i appears 39 times in 17 of its 7,391 classes: <0.01% of all instructions, the 173rd most common of 194 opcodes in use. Some of the methods that use it: java.io.ObjectOutputStream$HandleTable.<init>, java.lang.Float.byteValue, java.lang.Math.round, java.lang.runtime.ExactConversionsSupport.isIntToFloatExact.

Example

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

static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25
… 11 instructions before
41long il = i;
14lstore 9// il
42float lf = l;
16lload_1 // l
17l2f
18fstore 11// lf
43int fi = (int) f;
20fload_3 // f
21f2i
22istore 12// fi
44long dl = (long) d;
24dload 4// d
26d2l
27lstore 13// dl
45float df = (float) d;
29dload 4// d
31d2f
… 61 instructions after

Open in the viewer

Related instructions

l2i Converts the long on top of the stack to int.f2l Converts the float on top of the stack to long.f2d Converts the float on top of the stack to double.

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