l2d 0x8a

Converts the long on top of the stack to double.

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

What it does

Converts the long on top of the stack to double.

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 double.

How often javac uses it

In JDK 25.0.5's java.base module, l2d appears 72 times in 33 of its 7,391 classes: <0.01% of all instructions, the 161st most common of 194 opcodes in use. Some of the methods that use it: java.lang.FdLibm$Pow.compute, java.lang.Long.doubleValue, java.lang.runtime.ExactConversionsSupport.isLongToDoubleExact, java.math.BigDecimal.doubleValue.

Example

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

static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25
… 35 instructions before
49float iff = i;
48fstore 21// iff
50double id = i;
50iload_0 // i
51i2d
52dstore 22// id
51double ld = l;
54lload_1 // l
55l2d
56dstore 24// ld
52int di = (int) d;
58dload 4// d
60d2i
61istore 26// di
53return b + c + s + il + lf + fi + dl + df + li + fd + fl + iff + id + ld + di;
63iload 6// b
65iload 7// c
… 37 instructions after

Open in the viewer

Related instructions

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

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