d2i 0x8e
Converts the double on top of the stack to int.
- Opcode
0x8e(142)- Family
- Conversions
- Operands
- none
- Length
- 1 byte
- Operand stack
…, value (double) → …, result (int)- Can throw
- nothing at run time (beyond linking errors)
What it does
Converts the double on top of the stack to int.
Rounds toward zero. NaN becomes 0, and values out of range become the int's minimum or maximum: the conversion saturates instead of wrapping.
How often javac uses it
In JDK 25.0.5's java.base module, d2i appears 45 times in 25 of its 7,391 classes: <0.01% of all instructions, the 169th most common of 194 opcodes in use. Some of the methods that use it: java.lang.ClassValue$ClassValueMap.sizeCache, java.lang.Double.byteValue, java.lang.FdLibm$Cos.__kernel_cos, java.lang.FdLibm$Exp.compute.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; d2i is highlighted.
static int locals(int a, int b, int c, int d, long e, double f) in Tour, compiled by javac 25Related instructions
l2i Converts the long on top of the stack to int.f2i Converts the float on top of the stack to int.d2l Converts the double on top of the stack to long.
Specification: JVMS §6.5, d2i (Java SE 25).