Contents | Prev | Next | Index | The Java^{TM} Virtual Machine Specification |

A B C D F G I J L M N P R S T W

**Operation**

Convert`float`

to`double`

Format

f2d

**Forms**

f2d= 141 (0x8d)

**Operand Stack**

...,value...,result

**Description**

Thevalueon 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 invalue'. Thenvalue'is converted to a`double`

result. Thisresultis pushed onto the operand stack.

**Notes**

Where anf2dinstruction 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 anf2dinstruction 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 operandvalueis taken from the float-extended-exponent value set and the target result is constrained to the double value set, rounding ofvaluemay be required.

**Operation**

Convert`float`

to`int`

Format

f2i

**Forms**

f2i= 139 (0x8b)

**Operand Stack**

...,value...,result

**Description**

Thevalueon 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 invalue'. Thenvalue'is converted to an`int`

result. Thisresultis pushed onto the operand stack:

- If the
*value'*is NaN, the*result*of the conversion is an`int`

0. - Otherwise, if the
*value'*is not an infinity, it is rounded to an integer value*V*, rounding towards zero using IEEE 754 round towards zero mode. If this integer value*V*can be represented as an`int`

, then the*result*is the`int`

value*V*. - Otherwise, either the
*value'*must be too small (a negative value of large magnitude or negative infinity), and the*result*is the smallest representable value of type`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**

Thef2iinstruction performs a narrowing primitive conversion (§2.6.3). It may lose information about the overall magnitude ofvalue'and may also lose precision.

**Operation**

Convert`float`

to`long`

Format

f2l

**Forms**

f2l= 140 (0x8c)

**Operand Stack**

...,value...,result

**Description**

Thevalueon 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 invalue'. Thenvalue'is converted to a`long`

result. Thisresultis pushed onto the operand stack:

- If the
*value'*is NaN, the*result*of the conversion is a`long`

0. - Otherwise, if the
*value'*is not an infinity, it is rounded to an integer value*V*, rounding towards zero using IEEE 754 round towards zero mode. If this integer value*V*can be represented as a`long`

, then the*result*is the`long`

value*V*. - Otherwise, either the
*value'*must be too small (a negative value of large magnitude or negative infinity), and the*result*is the smallest representable value of type`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**

Thef2linstruction performs a narrowing primitive conversion (§2.6.3). It may lose information about the overall magnitude ofvalue'and may also lose precision.

**Operation**

Add`float`

Format

fadd

**Forms**

fadd= 98 (0x62)

**Operand Stack**

...,value1,value2...,result

**Description**

Bothvalue1andvalue2must be of type`float`

. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting invalue1'andvalue2'. The`float`

resultisvalue1'+value2'. Theresultis pushed onto the operand stack.

The result of anfaddinstruction is governed by the rules of IEEE arithmetic:

- If either
*value1'*or*value2'*is NaN, the result is NaN. - The sum of two infinities of opposite sign is NaN.
- The sum of two infinities of the same sign is the infinity of that sign.
- The sum of an infinity and any finite value is equal to the infinity.
- The sum of two zeroes of opposite sign is positive zero.
- The sum of two zeroes of the same sign is the zero of that sign.
- The sum of a zero and a nonzero finite value is equal to the nonzero value.
- The sum of two nonzero finite values of the same magnitude and opposite sign is positive zero.

- In the remaining cases, where neither operand is an infinity, a zero, or NaN and the values have the same sign or have different magnitudes, the sum is computed and rounded to the nearest representable value 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, or loss of precision may occur, execution of anfaddinstruction never throws a runtime exception.

**Operation**

Load`float`

from array

Format

faload

**Forms**

faload= 48 (0x30)

**Operand Stack**

...,arrayref,index...,value

**Description**

Thearrayrefmust be of type`reference`

and must refer to an array whose components are of type`float`

. Theindexmust be of type`int`

. Botharrayrefandindexare popped from the operand stack. The`float`

valuein the component of the array atindexis retrieved and pushed onto the operand stack.

**Runtime Exceptions**

Ifarrayrefis`null`

,faloadthrows a`NullPointerException`

.

Otherwise, ifindexis not within the bounds of the array referenced byarrayref, thefaloadinstruction throws an`ArrayIndexOutOfBoundsException`

.

**Operation**

Store into`float`

array

Format

fastore

**Forms**

fastore= 81 (0x51)

**Operand Stack**

...,arrayref,index,value...

**Description**

Thearrayrefmust be of type`reference`

and must refer to an array whose components are of type`float`

. Theindexmust be of type`int`

, and thevaluemust be of type`float`

. Thearrayref,index, andvalueare popped from the operand stack. The`float`

valueundergoes value set conversion (§3.8.3), resulting invalue', andvalue'is stored as the component of the array indexed byindex.

**Runtime Exceptions**

Ifarrayrefis`null`

,fastorethrows a`NullPointerException`

.

Otherwise, ifindexis not within the bounds of the array referenced byarrayref, thefastoreinstruction throws an`ArrayIndexOutOfBoundsException`

.

**Operation**

Compare`float`

Format

fcmp<op>

**Forms**

fcmpg= 150 (0x96)fcmpl= 149 (0x95)

**Operand Stack**

...,value1,value2...,result

**Description**

Bothvalue1andvalue2must be of type`float`

. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting invalue1'andvalue2'. A floating-point comparison is performed:

- If
*value1'*is greater than*value2'*, the`int`

value*1*is pushed onto the operand stack. - Otherwise, if
*value1'*is equal to*value2'*, the`int`

value*0*is pushed onto the operand stack. - Otherwise, if
*value1'*is less than*value2'*, the`int`

value -*1*is pushed onto the operand stack. - Otherwise, at least one of
*value1'*or*value2'*is NaN. The*fcmpg*instruction pushes the`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**

Thefcmpgandfcmplinstructions differ only in their treatment of a comparison involving NaN. NaN is unordered, so any`float`

comparison fails if either or both of its operands are NaN. With bothfcmpgandfcmplavailable, any`float`

comparison may be compiled to push the sameresultonto 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**

Push`float`

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, or2.0) onto the operand stack.

**Operation**

Divide`float`

Format

fdiv

**Forms**

fdiv= 110 (0x6e)

**Operand Stack**

...,value1,value2...,result

**Description**

Bothvalue1andvalue2must be of type`float`

. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting invalue1'andvalue2'. The`float`

resultisvalue1'/value2'. Theresultis pushed onto the operand stack.

The result of anfdivinstruction is governed by the rules of IEEE arithmetic:

- If either
*value1'*or*value2'*is NaN, the result is NaN. - If neither
*value1'*nor*value2'*is NaN, the sign of the result is positive if both values have the same sign, negative if the values have different signs. - Division of an infinity by an infinity results in NaN.
- Division of an infinity by a finite value results in a signed infinity, with the sign-producing rule just given.
- Division of a finite value by an infinity results in a signed zero, with the sign-producing rule just given.
- Division of a zero by a zero results in NaN; division of zero by any other finite value results in a signed zero, with the sign-producing rule just given.
- Division of a nonzero finite value by a zero results in a signed infinity, with the sign-producing rule just given.

- In the remaining cases, where neither operand is an infinity, a zero, or NaN, the quotient is computed and rounded to the nearest
`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 anfdivinstruction never throws a runtime exception.

**Operation**

Load`float`

from local variable

Format

floadindex

**Forms**

fload= 23 (0x17)

**Operand Stack**

... ...,value

**Description**

Theindexis an unsigned byte that must be an index into the local variable array of the current frame (§3.6). The local variable atindexmust contain a`float`

. Thevalueof the local variable atindexis pushed onto the operand stack.

**Notes**

Thefloadopcode can be used in conjunction with thewideinstruction to access a local variable using a two-byte unsigned index.

**Operation**

Load`float`

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`

. Thevalueof the local variable at<n>is pushed onto the operand stack.

**Notes**

Each of thefload_<n>instructions is the same asfloadwith anindexof<n>, except that the operand<n>is implicit.

**Operation**

Multiply`float`

Format

fmul

**Forms**

fmul= 106 (0x6a)

**Operand Stack**

...,value1,value2...,result

**Description**

Bothvalue1andvalue2must be of type`float`

. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting invalue1'andvalue2'. The`float`

resultisvalue1'*value2'. Theresultis pushed onto the operand stack.

The result of anfmulinstruction is governed by the rules of IEEE arithmetic:

- If either
*value1'*or*value2'*is NaN, the result is NaN. - If neither
*value1'*nor*value2'*is NaN, the sign of the result is positive if both values have the same sign, and negative if the values have different signs. - Multiplication of an infinity by a zero results in NaN.
- Multiplication of an infinity by a finite value results in a signed infinity, with the sign-producing rule just given.
- In the remaining cases, where neither an infinity nor NaN is involved, the product is computed and rounded to the nearest representable value 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, or loss of precision may occur, execution of anfmulinstruction never throws a runtime exception.

**Operation**

Negate`float`

Format

fneg

**Forms**

fneg= 118 (0x76)

**Operand Stack**

...,value...,result

**Description**

Thevaluemust be of type`float`

. It is popped from the operand stack and undergoes value set conversion (§3.8.3), resulting invalue'. The`float`

resultis the arithmetic negation ofvalue'. Thisresultis pushed onto the operand stack.

For`float`

values, negation is not the same as subtraction from zero. If`x`

is +`0.0`

, then`0.0`

-`x`

equals +`0.0`

, but -`x`

equals -`0.0`

. Unary minus merely inverts the sign of a`float`

.

Special cases of interest:

- If the operand is NaN, the result is NaN (recall that NaN has no sign).
- If the operand is an infinity, the result is the infinity of opposite sign.
- If the operand is a zero, the result is the zero of opposite sign.

**Operation**

Remainder`float`

Format

frem

**Forms**

frem= 114 (0x72)

**Operand Stack**

...,value1,value2...,result

**Description**

Bothvalue1andvalue2must be of type`float`

. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting invalue1'andvalue2'. Theresultis calculated and pushed onto the operand stack as a`float`

.

Theresultof anfreminstruction 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 isnotanalogous to that of the usual integer remainder operator. Instead, the Java virtual machine definesfremto behave in a manner analogous to that of the Java virtual machine integer remainder instructions (iremandlrem); this may be compared with the C library function`fmod`

.

The result of anfreminstruction is governed by these rules:

- If either
*value1'*or*value2'*is NaN, the result is NaN. - If neither
*value1'*nor*value2'*is NaN, the sign of the result equals the sign of the dividend. - If the dividend is an infinity or the divisor is a zero or both, the result is NaN.
- If the dividend is finite and the divisor is an infinity, the result equals the dividend.

- If the dividend is a zero and the divisor is finite, the result equals the dividend.
- In the remaining cases, where neither operand is an infinity, a zero, or NaN, the floating-point remainder
*result**value1'*and a divisor*value2'*is defined by the mathematical relation*result*=*value1'*-*value2'***q*), where*q*is an integer that is negative only if*value1'*/*value2'*is negative and positive only if*value1'*/*value2'*is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of*value1'*and*value2'*.

Despite the fact that division by zero may occur, evaluation of anfreminstruction 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**

Return`float`

from method

Format

freturn

**Forms**

freturn= 174 (0xae)

**Operand Stack**

...,value[empty]

**Description**

The current method must have return type`float`

. Thevaluemust be of type`float`

. If the current method is a`synchronized`

method, the monitor acquired or reentered on invocation of the method is released or exited (respectively) as if by execution of amonitorexitinstruction. If no exception is thrown,valueis popped from the operand stack of the current frame (§3.6) and undergoes value set conversion (§3.8.3), resulting invalue'. Thevalue'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 a`synchronized`

method and the current thread is not the owner of the monitor acquired or reentered on invocation of the method,freturnthrows an`IllegalMonitorStateException`

. This can happen, for example, if a`synchronized`

method contains amonitorexitinstruction, but nomonitorenterinstruction, 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, thenfreturnthrows an`IllegalMonitorStateException`

.

**Operation**

Store`float`

into local variable

Format

fstoreindex

**Forms**

fstore= 56 (0x38)

**Operand Stack**

...,value...

**Description**

Theindexis an unsigned byte that must be an index into the local variable array of the current frame (§3.6). Thevalueon 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 invalue'. The value of the local variable atindexis set tovalue'.

**Notes**

Thefstoreopcode can be used in conjunction with thewideinstruction to access a local variable using a two-byte unsigned index.

**Operation**

Store`float`

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). Thevalueon 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 invalue'. The value of the local variable at<n>is set tovalue'.

**Notes**

Each of thefstore_<n>is the same asfstorewith anindexof<n>, except that the operand<n>is implicit.

**Operation**

Subtract`float`

Format

fsub

**Forms**

fsub= 102 (0x66)

**Operand Stack**

...,value1,value2...,result

**Description**

Bothvalue1andvalue2must be of type`float`

. The values are popped from the operand stack and undergo value set conversion (§3.8.3), resulting invalue1'andvalue2'. The`float`

resultisvalue1'-value2'. Theresultis pushed onto the operand stack.

For`float`

subtraction, it is always the case that`a`

-`b`

produces the same result as`a`

+(-`b`

). However, for thefsubinstruction, subtraction from zero is not the same as negation, because if`x`

is +`0.0`

, then`0.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 anfsubinstruction never throws a runtime exception.

Contents | Prev | Next | Index

*The Java*^{TM}* Virtual Machine Specification *

*Copyright © 1999 Sun Microsystems, Inc.
All rights reserved*

Please send any comments or corrections to jvm@java.sun.com