l2f 0x89

Converts the long on top of the stack to float.

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

What it does

Converts the long 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 long has an exact float.

How often javac uses it

In JDK 25.0.5's java.base module, l2f appears 14 times in 11 of its 7,391 classes: <0.01% of all instructions, the 183rd most common of 194 opcodes in use. Some of the methods that use it: java.lang.Long.floatValue, java.lang.runtime.ExactConversionsSupport.isLongToFloatExact, java.math.BigDecimal.floatValue, java.math.BigInteger.floatValue.

Example

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

static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25
… 8 instructions before
40short s = (short) i;
10istore 8// s
41long il = i;
12iload_0 // i
13i2l
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
… 64 instructions after

Open in the viewer

Related instructions

i2f Converts the int on top of the stack to float.l2i Converts the long on top of the stack to int.l2d Converts the long on top of the stack to double.

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