Convert int
to float
Bytecode
Type | Description |
u1 | i2f opcode = 0x86 (134) |
Stack ..., value => ..., result
Description
Pops an int off the operand stack, casts it into a single-precision float, and pushes the float back onto the stack. Notice that there is may be a loss of precision (floats have 24 bits of significand, as compared to 32 bits for an int, so the least significant bits of int are lost). However, the magnitude of the result will be preserved (the range of a float is greater than the range of an int). Rounding is done using the IEEE 754 round-to-nearest mode.
The value on the top of the operand stack must be of type int
. It
is popped from the operand stack and converted to the float
result
using IEEE 754 round-to-nearest mode. The result is pushed onto the operand stack.
The i2f instruction performs a widening primitive conversion, but may result in
a loss of precision because type float
has only 24 mantissa bits.