i2d 0x87

Converts the int on top of the stack to double.

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

What it does

Converts the int 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.

How often javac uses it

In JDK 25.0.5's java.base module, i2d appears 92 times in 36 of its 7,391 classes: <0.01% of all instructions, the 159th most common of 194 opcodes in use. Some of the methods that use it: java.io.StreamTokenizer.nextToken, java.lang.Byte.doubleValue, java.lang.ClassValue$ClassValueMap.sizeCache, java.lang.FdLibm$Exp.compute.

Examples

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

double length() in Point, compiled by javac 25
9return Math.sqrt(x * x + y * y);
0aload_0 // this
1getfield #14// Point.x : int
4aload_0 // this
5getfield #14// Point.x : int
9aload_0 // this
10getfield #20// Point.y : int
13aload_0 // this
14getfield #20// Point.y : int
17imul
18iadd
19i2d
20invokestatic #23// Math.sqrt(double) : double

Open in the viewer

static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25
… 32 instructions before
48long fl = (long) f;
44lstore 19// fl
49float iff = i;
46iload_0 // i
47i2f
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
… 40 instructions after

Open in the viewer

Related instructions

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

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