Convert float
to int
Bytecode
Type | Description |
u1 | f2i opcode = 0x8B (139) |
Stack ..., value => ..., result
Description
Pops a single precision float off of the stack, casts it to a 32-bit int, and pushes the
int value back onto the stack.
Rounding is done using IEEE 754 round-to-nearest mode. The fractional part is lost by rounding towards zero, so (int)-3.14 becomes -3.
If the original float value is NaN, the result is 0. If the value is too large to be represented as an integer, or if it is positive infinity, the result is the largest possible integer 0x7FFFFFFF. If the value is too small (i.e. a negative value of large magnitude, or negative infinity) then the result is the most negative integer 0x80000000.
The value on the top of the operand stack must be of type float
. It
is popped from the operand stack and converted to an int
. The result
is pushed onto the operand stack:
int
0. int
, then the result is the int
value V. int
, or the value must be too large (a positive value of large
magnitude or positive infinity), and the result is the largest representable value
of type int
. The f2i instruction performs a narrowing primitive conversion. It may lose information about the overall magnitude of value, and may also lose precision.