Contents | Prev | Next | Index | The JavaTM Virtual Machine Specification |
Operation
Convertfloat
todouble
Format
f2d
Forms
f2d = 141 (0x8d)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typefloat
. It is popped from the operand stack and undergoes value set conversion (§3.8.3), resulting in value'. Then value' is converted to adouble
result. This result is pushed onto the operand stack.
Notes
Where an f2d instruction is FP-strict (§3.8.2) it performs a widening primitive conversion (§2.6.2). Because all values of the float value set (§3.3.2) are exactly representable by values of the double value set (§3.3.2), such a conversion is exact.
Where an f2d instruction is not FP-strict, the result of the conversion may be taken from the double-extended-exponent value set; it is not necessarily rounded to the nearest representable value in the double value set. However, if the operand value is taken from the float-extended-exponent value set and the target result is constrained to the double value set, rounding of value may be required.
Operation
Convertfloat
toint
Format
f2i
Forms
f2i = 139 (0x8b)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typefloat
. It is popped from the operand stack and undergoes value set conversion (§3.8.3), resulting in value'. Then value' is converted to anint
result. This 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
.
Notes
The f2i instruction performs a narrowing primitive conversion (§2.6.3). It may lose information about the overall magnitude of value' and may also lose precision.
Operation
Convertfloat
tolong
Format
f2l
Forms
f2l = 140 (0x8c)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typefloat
. It is popped from the operand stack and undergoes value set conversion (§3.8.3), resulting in value'. Then value' is converted to along
result. This result is pushed onto the operand stack:
long
0.
long
, then the result is the long
value V.
long
, 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 long
.
Notes
The f2l instruction performs a narrowing primitive conversion (§2.6.3). It may lose information about the overall magnitude of value' and may also lose precision.
Operation
Addfloat
Format
fadd
Forms
fadd = 98 (0x62)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typefloat
. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. Thefloat
result is value1' + value2'. The result is pushed onto the operand stack.
The result of an fadd instruction is governed by the rules of IEEE arithmetic:
float
, we say the operation overflows; the result is then an infinity of appropriate sign. If the magnitude is too small to represent as a float
, we say the operation underflows; the result is then a zero of appropriate sign.
The Java virtual machine requires support of gradual underflow as defined by IEEE 754. Despite the fact that overflow, underflow, or loss of precision may occur, execution of an fadd instruction never throws a runtime exception.
Operation
Loadfloat
from array
Format
faload
Forms
faload = 48 (0x30)
Operand Stack
..., arrayref, index ..., value
Description
The arrayref must be of typereference
and must refer to an array whose components are of typefloat
. The index must be of typeint
. Both arrayref and index are popped from the operand stack. Thefloat
value in the component of the array at index is retrieved and pushed onto the operand stack.
Runtime Exceptions
If arrayref isnull
, faload throws aNullPointerException
.
Otherwise, if index is not within the bounds of the array referenced by arrayref, the faload instruction throws an ArrayIndexOutOfBoundsException
.
Operation
Store intofloat
array
Format
fastore
Forms
fastore = 81 (0x51)
Operand Stack
..., arrayref, index, value ...
Description
The arrayref must be of typereference
and must refer to an array whose components are of typefloat
. The index must be of typeint
, and the value must be of typefloat
. The arrayref, index, and value are popped from the operand stack. Thefloat
value undergoes value set conversion (§3.8.3), resulting in value', and value' is stored as the component of the array indexed by index.
Runtime Exceptions
If arrayref isnull
, fastore throws aNullPointerException
.
Otherwise, if index is not within the bounds of the array referenced by arrayref, the fastore instruction throws an ArrayIndexOutOfBoundsException
.
Operation
Comparefloat
Format
fcmp<op>
Forms
fcmpg = 150 (0x96) fcmpl = 149 (0x95)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of type float
. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. A floating-point comparison is performed:
int
value 1 is pushed onto the operand stack. int
value 0 is pushed onto the operand stack.int
value -1 is pushed onto the operand stack. int
value 1 onto the operand stack and the fcmpl instruction pushes the int
value -1 onto the operand stack.
Floating-point comparison is performed in accordance with IEEE 754. All values other than NaN are ordered, with negative infinity less than all finite values and positive infinity greater than all finite values. Positive zero and negative zero are considered equal.
Notes
The fcmpg and fcmpl instructions differ only in their treatment of a comparison involving NaN. NaN is unordered, so anyfloat
comparison fails if either or both of its operands are NaN. With both fcmpg and fcmpl available, anyfloat
comparison may be compiled to push the same result onto the operand stack whether the comparison fails on non-NaN values or fails because it encountered a NaN. For more information, see Section 7.5, "More Control Examples."
Operation
Pushfloat
Format
fconst_<f>
Forms
fconst_0 = 11 (0xb) fconst_1 = 12 (0xc) fconst_2 = 13 (0xd)
Operand Stack
... ..., <f>
Description
Push the float
constant <f> (0.0, 1.0, or 2.0) onto the operand stack.
Operation
Dividefloat
Format
fdiv
Forms
fdiv = 110 (0x6e)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typefloat
. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. Thefloat
result is value1' / value2'. The result is pushed onto the operand stack.
The result of an fdiv instruction is governed by the rules of IEEE arithmetic:
float
using IEEE 754 round to nearest mode. If the magnitude is too large to represent as a float
, we say the operation overflows; the result is then an infinity of appropriate sign. If the magnitude is too small to represent as a float
, we say the operation underflows; the result is then a zero of appropriate sign.
The Java virtual machine requires support of gradual underflow as defined by IEEE 754. Despite the fact that overflow, underflow, division by zero, or loss of precision may occur, execution of an fdiv instruction never throws a runtime exception.
Operation
Loadfloat
from local variable
Format
fload index
Forms
fload = 23 (0x17)
Operand Stack
... ..., value
Description
The index is an unsigned byte that must be an index into the local variable array of the current frame (§3.6). The local variable at index must contain a float
. The value of the local variable at index is pushed onto the operand stack.
Notes
The fload opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index.
Operation
Loadfloat
from local variable
Format
fload_<n>
Forms
fload_0 = 34 (0x22) fload_1 = 35 (0x23) fload_2 = 36 (0x24) fload_3 = 37 (0x25)
Operand Stack
... ..., value
Description
The <n> must be an index into the local variable array of the current frame (§3.6). The local variable at <n> must contain a float
. The value of the local variable at <n> is pushed onto the operand stack.
Notes
Each of the fload_<n> instructions is the same as fload with an index of <n>, except that the operand <n> is implicit.
Operation
Multiplyfloat
Format
fmul
Forms
fmul = 106 (0x6a)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typefloat
. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. Thefloat
result is value1' * value2'. The result is pushed onto the operand stack.
The result of an fmul instruction is governed by the rules of IEEE arithmetic:
float
, we say the operation overflows; the result is then an infinity of appropriate sign. If the magnitude is too small to represent as a float
, we say the operation underflows; the result is then a zero of appropriate sign.
The Java virtual machine requires support of gradual underflow as defined by IEEE 754. Despite the fact that overflow, underflow, or loss of precision may occur, execution of an fmul instruction never throws a runtime exception.
Operation
Negatefloat
Format
fneg
Forms
fneg = 118 (0x76)
Operand Stack
..., value ..., result
Description
The value must be of typefloat
. It is popped from the operand stack and undergoes value set conversion (§3.8.3), resulting in value'. Thefloat
result is the arithmetic negation of value'. This result is pushed onto the operand stack.
Forfloat
values, negation is not the same as subtraction from zero. Ifx
is +0.0
, then0.0
-x
equals +0.0
, but -x
equals -0.0
. Unary minus merely inverts the sign of afloat
.
Special cases of interest:
Operation
Remainderfloat
Format
frem
Forms
frem = 114 (0x72)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typefloat
. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. The result is calculated and pushed onto the operand stack as afloat
.
The result of an frem instruction is not the same as that of the so-called remainder operation defined by IEEE 754. The IEEE 754 "remainder" operation computes the remainder from a rounding division, not a truncating division, and so its behavior is not analogous to that of the usual integer remainder operator. Instead, the Java virtual machine defines frem to behave in a manner analogous to that of the Java virtual machine integer remainder instructions (irem and lrem); this may be compared with the C library function fmod
.
The result of an frem instruction is governed by these rules:
Despite the fact that division by zero may occur, evaluation of an frem instruction never throws a runtime exception. Overflow, underflow, or loss of precision cannot occur.
Notes
The IEEE 754 remainder operation may be computed by the library routine Math.IEEEremainder
.
Operation
Returnfloat
from method
Format
freturn
Forms
freturn = 174 (0xae)
Operand Stack
..., value [empty]
Description
The current method must have return typefloat
. The value must be of typefloat
. If the current method is asynchronized
method, the monitor acquired or reentered on invocation of the method is released or exited (respectively) as if by execution of a monitorexit instruction. If no exception is thrown, value is popped from the operand stack of the current frame (§3.6) and undergoes value set conversion (§3.8.3), resulting in value'. The value' is pushed onto the operand stack of the frame of the invoker. Any other values on the operand stack of the current method are discarded.
The interpreter then returns control to the invoker of the method, reinstating the frame of the invoker.
Runtime Exceptions
If the current method is asynchronized
method and the current thread is not the owner of the monitor acquired or reentered on invocation of the method, freturn throws anIllegalMonitorStateException
. This can happen, for example, if asynchronized
method contains a monitorexit instruction, but no monitorenter instruction, on the object on which the method is synchronized.
Otherwise, if the virtual machine implementation enforces the rules on structured use of locks described in §8.13 and if the first of those rules is violated during invocation of the current method, then freturn throws an IllegalMonitorStateException
.
Operation
Storefloat
into local variable
Format
fstore index
Forms
fstore = 56 (0x38)
Operand Stack
..., value ...
Description
The index is an unsigned byte that must be an index into the local variable array of the current frame (§3.6). The value on the top of the operand stack must be of type float
. It is popped from the operand stack and undergoes value set conversion (§3.8.3), resulting in value'. The value of the local variable at index is set to value'.
Notes
The fstore opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index.
Operation
Storefloat
into local variable
Format
fstore_<n>
Forms
fstore_0 = 67 (0x43) fstore_1 = 68 (0x44) fstore_2 = 69 (0x45) fstore_3 = 70 (0x46)
Operand Stack
..., value ...
Description
The <n> must be an index into the local variable array of the current frame (§3.6). The value on the top of the operand stack must be of type float
. It is popped from the operand stack and undergoes value set conversion (§3.8.3), resulting in value'. The value of the local variable at <n> is set to value'.
Notes
Each of the fstore_<n> is the same as fstore with an index of <n>, except that the operand <n> is implicit.
Operation
Subtractfloat
Format
fsub
Forms
fsub = 102 (0x66)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typefloat
. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. Thefloat
result is value1' - value2'. The result is pushed onto the operand stack.
Forfloat
subtraction, it is always the case thata
-b
produces the same result asa
+(-b
). However, for the fsub instruction, subtraction from zero is not the same as negation, because ifx
is +0.0
, then0.0
-x
equals +0.0
, but -x
equals -0.0
.
The Java virtual machine requires support of gradual underflow as defined by IEEE 754. Despite the fact that overflow, underflow, or loss of precision may occur, execution of an fsub instruction never throws a runtime exception.
Contents | Prev | Next | Index
The JavaTM Virtual Machine Specification
Copyright © 1999 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to jvm@java.sun.com