d2f 0x90
Converts the double on top of the stack to float.
- Opcode
0x90(144)- Family
- Conversions
- Operands
- none
- Length
- 1 byte
- Operand stack
…, value (double) → …, result (float)- Can throw
- nothing at run time (beyond linking errors)
What it does
Converts the double on top of the stack to float.
Rounds toward zero. NaN becomes 0, and values out of range become the float's minimum or maximum: the conversion saturates instead of wrapping.
How often javac uses it
In JDK 25.0.5's java.base module, d2f appears 12 times in 8 of its 7,391 classes: <0.01% of all instructions, the 184th most common of 194 opcodes in use. Some of the methods that use it: java.lang.Double.floatValue, java.lang.Float.<init>, java.lang.Math.fma, java.lang.runtime.ExactConversionsSupport.isDoubleToFloatExact.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; d2f is highlighted.
static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25Related instructions
i2f Converts the int on top of the stack to float.l2f Converts the long on top of the stack to float.d2i Converts the double on top of the stack to int.
Specification: JVMS §6.5, d2f (Java SE 25).