f2d 0x8d

Converts the float on top of the stack to double.

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

What it does

Converts the float 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, f2d appears 29 times in 13 of its 7,391 classes: <0.01% of all instructions, the 178th most common of 194 opcodes in use. Some of the methods that use it: java.lang.Float.toHexString, java.lang.Math.fma, java.lang.runtime.ExactConversionsSupport.isDoubleToFloatExact, java.lang.String.scale.

Examples

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

static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25
… 23 instructions before
45float df = (float) d;
32fstore 15// df
46int li = (int) l;
34lload_1 // l
35l2i
36istore 16// li
47double fd = f;
38fload_3 // f
39f2d
40dstore 17// fd
48long fl = (long) f;
42fload_3 // f
43f2l
44lstore 19// fl
49float iff = i;
46iload_0 // i
47i2f
… 49 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
… 9 instructions before
30long r = a * b + c - d;
10lsub
11lstore 10// r
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
… 48 instructions after

Open in the viewer

Related instructions

i2d Converts the int on top of the stack to double.l2d Converts the long on top of the stack to double.f2i Converts the float on top of the stack to int.

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