Contents | Prev | Next | Index | The JavaTM Virtual Machine Specification |
Operation
Convertdouble
tofloat
Format
d2f
Forms
d2f = 144 (0x90)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typedouble
. It is popped from the operand stack and undergoes value set conversion (§3.8.3) resulting in value'. Then value' is converted to afloat
result using IEEE 754 round to nearest mode. The result is pushed onto the operand stack.
Where an d2f instruction is FP-strict (§3.8.2), the result of the conversion is always rounded to the nearest representable value in the float value set (§3.3.2).
Where an d2f instruction is not FP-strict, the result of the conversion may be taken from the float-extended-exponent value set (§3.3.2); it is not necessarily rounded to the nearest representable value in the float value set.
A finite value' too small to be represented as afloat
is converted to a zero of the same sign; a finite value' too large to be represented as afloat
is converted to an infinity of the same sign. Adouble
NaN is converted to afloat
NaN.
Notes
The d2f 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
Convertdouble
toint
Format
d2i
Forms
d2i = 142 (0x8e)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typedouble
. It is popped from the operand stack and undergoes value set conversion (§3.8.3) resulting in value'. Then value' is converted to anint
. 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
.
Notes
The d2i 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
Convertdouble
tolong
Format
d2l
Forms
d2l = 143 (0x8f)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typedouble
. It is popped from the operand stack and undergoes value set conversion (§3.8.3) resulting in value'. Then value' is converted to along
. The 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 d2l 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
Adddouble
Format
dadd
Forms
dadd = 99 (0x63)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typedouble
. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. Thedouble
result is value1' + value2'. The result is pushed onto the operand stack.
The result of a dadd instruction is governed by the rules of IEEE arithmetic:
double
, we say the operation overflows; the result is then an infinity of appropriate sign. If the magnitude is too small to represent as a double
, 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 a dadd instruction never throws a runtime exception.
Operation
Loaddouble
from array
Format
daload
Forms
daload = 49 (0x31)
Operand Stack
..., arrayref, index ..., value
Description
The arrayref must be of typereference
and must refer to an array whose components are of typedouble
. The index must be of typeint
. Both arrayref and index are popped from the operand stack. Thedouble
value in the component of the array at index is retrieved and pushed onto the operand stack.
Runtime Exceptions
If arrayref isnull
, daload throws aNullPointerException
.
Otherwise, if index is not within the bounds of the array referenced by arrayref, the daload instruction throws an ArrayIndexOutOfBoundsException
.
Operation
Store intodouble
array
Format
dastore
Forms
dastore = 82 (0x52)
Operand Stack
..., arrayref, index, value ...
Description
The arrayref must be of typereference
and must refer to an array whose components are of typedouble
. The index must be of typeint
, and value must be of typedouble
. The arrayref, index, and value are popped from the operand stack. Thedouble
value undergoes value set conversion (§3.8.3), resulting in value', which is stored as the component of the array indexed by index.
Runtime Exceptions
If arrayref isnull
, dastore throws aNullPointerException
.
Otherwise, if index is not within the bounds of the array referenced by arrayref, the dastore instruction throws anArrayIndexOutOfBounds
Exception
.
Operation
Comparedouble
Format
dcmp<op>
Forms
dcmpg = 152 (0x98) dcmpl = 151 (0x97)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of type double
. 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 dcmpl 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 dcmpg and dcmpl instructions differ only in their treatment of a comparison involving NaN. NaN is unordered, so anydouble
comparison fails if either or both of its operands are NaN. With both dcmpg and dcmpl available, anydouble
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
Pushdouble
Format
dconst_<d>
Forms
dconst_0 = 14 (0xe) dconst_1 = 15 (0xf)
Operand Stack
... ..., <d>
Description
Push the double
constant <d> (0.0 or 1.0) onto the operand stack.
Operation
Dividedouble
Format
ddiv
Forms
ddiv = 111 (0x6f)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typedouble
. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. Thedouble
result is value1' / value2'. The result is pushed onto the operand stack.
The result of a ddiv instruction is governed by the rules of IEEE arithmetic:
double
using IEEE 754 round to nearest mode. If the magnitude is too large to represent as a double
, we say the operation overflows; the result is then an infinity of appropriate sign. If the magnitude is too small to represent as a double
, 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 a ddiv instruction never throws a runtime exception.
Operation
Loaddouble
from local variable
Format
dload index
Forms
dload = 24 (0x18)
Operand Stack
... ..., value
Description
The index is an unsigned byte. Both index and index + 1 must be indices into the local variable array of the current frame (§3.6). The local variable at index must contain a double
. The value of the local variable at index is pushed onto the operand stack.
Notes
The dload opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index.
Operation
Loaddouble
from local variable
Format
dload_<n>
Forms
dload_0 = 38 (0x26) dload_1 = 39 (0x27) dload_2 = 40 (0x28) dload_3 = 41 (0x29)
Operand Stack
... ..., value
Description
Both <n> and <n> + 1 must be indices into the local variable array of the current frame (§3.6). The local variable at <n> must contain a double
. The value of the local variable at <n> is pushed onto the operand stack.
Notes
Each of the dload_<n> instructions is the same as dload with an index of <n>, except that the operand <n> is implicit.
Operation
Multiplydouble
Format
dmul
Forms
dmul = 107 (0x6b)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typedouble
. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. Thedouble
result is value1' * value2'. The result is pushed onto the operand stack.
The result of a dmul instruction is governed by the rules of IEEE arithmetic:
double
, we say the operation overflows; the result is then an infinity of appropriate sign. If the magnitude is too small to represent as a double
, 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 a dmul instruction never throws a runtime exception.
Operation
Negatedouble
Format
dneg
Forms
dneg = 119 (0x77)
Operand Stack
..., value ..., result
Description
The value must be of typedouble
. It is popped from the operand stack and undergoes value set conversion (§3.8.3), resulting in value'. Thedouble
result is the arithmetic negation of value'. The result is pushed onto the operand stack.
Fordouble
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 adouble
.
Special cases of interest:
Operation
Remainderdouble
Format
drem
Forms
drem = 115 (0x73)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typedouble
. 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 adouble
.
The result of a drem 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 drem 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 a drem instruction is governed by these rules:
Despite the fact that division by zero may occur, evaluation of a drem 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
Returndouble
from method
Format
dreturn
Forms
dreturn = 175 (0xaf)
Operand Stack
..., value [empty]
Description
The current method must have return typedouble
. The value must be of typedouble
. 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, dreturn 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 dreturn throws an IllegalMonitorStateException
.
Operation
Storedouble
into local variable
Format
dstore index
Forms
dstore = 57 (0x39)
Operand Stack
..., value ...
Description
The index is an unsigned byte. Both index and index + 1 must be indices into the local variable array of the current frame (§3.6). The value on the top of the operand stack must be of type double
. It is popped from the operand stack and undergoes value set conversion (§3.8.3), resulting in value'. The local variables at index and index + 1 are set to value'.
Notes
The dstore opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index.
Operation
Storedouble
into local variable
Format
dstore_<n>
Forms
dstore_0 = 71 (0x47) dstore_1 = 72 (0x48) dstore_2 = 73 (0x49) dstore_3 = 74 (0x4a)
Operand Stack
..., value ...
Description
Both <n> and <n> + 1 must be indices into the local variable array of the current frame (§3.6). The value on the top of the operand stack must be of type double
. It is popped from the operand stack and undergoes value set conversion (§3.8.3), resulting in value'. The local variables at <n> and <n> + 1 are set to value'.
Notes
Each of the dstore_<n> instructions is the same as dstore with an index of <n>, except that the operand <n> is implicit.
Operation
Subtractdouble
Format
dsub
Forms
dsub = 103 (0x67)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typedouble
. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting in value1' and value2'. Thedouble
result is value1' - value2'. The result is pushed onto the operand stack.
Fordouble
subtraction, it is always the case thata
-b
produces the same result asa
+(-b
). However, for the dsub 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 a dsub instruction never throws a runtime exception.
Operation
Duplicate the top operand stack value
Format
dup
Forms
dup = 89 (0x59)
Operand Stack
..., value ..., value, value
Description
Duplicate the top value on the operand stack and push the duplicated value onto the operand stack.
The dup instruction must not be used unless value is a value of a category 1 computational type (§3.11.1).
Operation
Duplicate the top operand stack value and insert two values down
Format
dup_x1
Forms
dup_x1 = 90 (0x5a)
Operand Stack
..., value2, value1 ..., value1, value2, value1
Description
Duplicate the top value on the operand stack and insert the duplicated value two values down in the operand stack.
The dup_x1 instruction must not be used unless both value1 and value2 are values of a category 1 computational type (§3.11.1).
Operation
Duplicate the top operand stack value and insert two or three values down
Format
dup_x2
Forms
dup_x2 = 91 (0x5b)
Operand Stack
Form 1:
..., value3, value2, value1 ..., value1, value3, value2, value1
where value1, value2, and value3 are all values of a category 1 computational type (§3.11.1).
Form 2:
..., value2, value1 ..., value1, value2, value1
where value1 is a value of a category 1 computational type and value2 is a value of a category 2 computational type (§3.11.1).
Description
Duplicate the top value on the operand stack and insert the duplicated value two or three values down in the operand stack.
Operation
Duplicate the top one or two operand stack values
Format
dup2
Forms
dup2 = 92 (0x5c)
Operand Stack
Form 1:
..., value2, value1 ..., value2, value1, value2, value1
where both value1 and value2 are values of a category 1 computational type (§3.11.1).
Form 2:
..., value ..., value, value
where value is a value of a category 2 computational type (§3.11.1).
Description
Duplicate the top one or two values on the operand stack and push the duplicated value or values back onto the operand stack in the original order.
Operation
Duplicate the top one or two operand stack values and insert two or three values down
Format
dup2_x1
Forms
dup2_x1 = 93 (0x5d)
Operand Stack
Form 1:
..., value3, value2, value1 ..., value2, value1, value3, value2, value1
where value1, value2, and value3 are all values of a category 1 computational type (§3.11.1).
Form 2:
..., value2, value1 ..., value1, value2, value1
where value1 is a value of a category 2 computational type and value2 is a value of a category 1 computational type (§3.11.1).
Description
Duplicate the top one or two values on the operand stack and insert the duplicated values, in the original order, one value beneath the original value or values in the operand stack.
Operation
Duplicate the top one or two operand stack values and insert two, three, or four values down
Format
dup2_x2
Forms
dup2_x2 = 94 (0x5e)
Operand Stack
Form 1:
..., value4, value3, value2, value1 ..., value2, value1, value4, value3, value2, value1
where value1, value2, value3, and value4 are all values of a category 1 computational type (§3.11.1).
Form 2:
..., value3, value2, value1 ..., value1, value3, value2, value1
where value1 is a value of a category 2 computational type and value2 and value3 are both values of a category 1 computational type (§3.11.1).
Form 3:
..., value3, value2, value1 ..., value2, value1, value3, value2, value1
where value1 and value2 are both values of a category 1 computational type and value3 is a value of a category 2 computational type (§3.11.1).
Form 4:
..., value2, value1 ..., value1, value2, value1
where value1 and value2 are both values of a category 2 computational type (§3.11.1).
Description
Duplicate the top one or two values on the operand stack and insert the duplicated values, in the original order, into the operand stack.
Contents | Prev | Next | Index
The JavaTM Virtual Machine Specification
Copyright © 1999 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to [email protected]