d2l 0x8f

Converts the double on top of the stack to long.

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

What it does

Converts the double 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, d2l appears 33 times in 16 of its 7,391 classes: <0.01% of all instructions, the 177th most common of 194 opcodes in use. Some of the methods that use it: java.lang.Double.longValue, java.lang.FdLibm$Pow.compute, java.lang.Math.round, java.lang.runtime.ExactConversionsSupport.isLongToDoubleExact.

Examples

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

static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25
… 14 instructions before
42float lf = l;
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
32fstore 15// df
46int li = (int) l;
34lload_1 // l
35l2i
… 58 instructions after

Open in the viewer

static long mix(long a, int b, short c, byte d, double e, float f, char g, boolean h) in Numbers, compiled by javac 25
… 11 instructions before
31r ^= (long) (e * f);
13lload 10// r
15dload 5// e
17fload 7// f
19f2d
20dmul
21d2l
22lxor
23lstore 10// r
32r += g;
25lload 10// r
27iload 8// g
29i2l
30ladd
… 46 instructions after

Open in the viewer

Related instructions

i2l Converts the int on top of the stack to long.f2l Converts the float on top of the stack to long.d2i Converts the double on top of the stack to int.

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