fneg 0x76

Negates the float on top of the stack.

Opcode
0x76 (118)
Family
Arithmetic and bitwise
Operands
none
Length
1 byte
Operand stack
…, value (float) → …, result (float)
Can throw
nothing at run time (beyond linking errors)

What it does

Negates the float on top of the stack: -x in Java. For floating point it flips the sign bit, so it turns 0.0 into -0.0, which subtracting from zero would not.

How often javac uses it

In JDK 25.0.5's java.base module, fneg appears 7 times in 2 of its 7,391 classes: <0.01% of all instructions, the 188th most common of 194 opcodes in use. Some of the methods that use it: java.util.Hashtable.hashCode, jdk.internal.math.FloatingDecimal$ASCIIToBinaryBuffer.floatValue.

Example

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

static float floats(float a, float b) in Tour, compiled by javac 25
… 10 instructions before
26x = x / b % 7f;
10fdiv
11ldc #13// 7
13frem
14fstore_2 // x
27return -x + 0f + 1f + 2f;
15fload_2 // x
16fneg
18fadd
20fadd
22fadd
… 1 instruction after

Open in the viewer

Related instructions

ineg Negates the int on top of the stack.lneg Negates the long on top of the stack.dneg Negates the double on top of the stack.

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