f2l 0x8c

Converts the float on top of the stack to long.

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

What it does

Converts the float on top of the stack to long.

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

How often javac uses it

In JDK 25.0.5's java.base module, f2l appears 5 times in 4 of its 7,391 classes: <0.01% of all instructions, the 191st most common of 194 opcodes in use. Some of the methods that use it: java.lang.Float.longValue, java.lang.runtime.ExactConversionsSupport.isLongToFloatExact, java.math.BigDecimal.floatValue, sun.invoke.util.ValueConversions.floatToLong.

Example

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

static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25
… 26 instructions before
46int li = (int) l;
36istore 16// li
47double fd = f;
38fload_3 // f
39f2d
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
… 46 instructions after

Open in the viewer

Related instructions

i2l Converts the int on top of the stack to long.f2i Converts the float on top of the stack to int.f2d Converts the float on top of the stack to double.

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