THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1
Returns the value obtained by rotating the bits in val to the right. In a right
rotation the low-order bit moved out on the right becomes the highest-order
bit on the left. Rotating to the right by a negative distance is the same as
rotating to the left by a positive distance.

Finally, the Integer and Long classes also define the mathematical signum function. This function takes
a value and returns 1, 0, or +1 as the value is negative, zero, or positive, respectively.


8.4.2. The Floating-Point Wrapper Classes


The Float and Double classes extend Number to represent the float and double types as classes.
With only a few exceptions, the names of the methods and constants are the same for both types. In the
following list, the types for the Float class are shown, but Float and float can be changed to Double
and double, respectively, to get equivalent fields and methods for the Double class. In addition to the
standard Number methods, Float and Double have the following constants and methods:


public final static floatPOSITIVE_INFINITY

The value for +.

public final static floatNEGATIVE_INFINITY

The value for -.

public final static floatNaN

Not-a-Number. This constant gives you a way to get a NaN value, not to test
one. Surprising as it may be, NaN==NaN is always false because a NaN
value, not being a number, is equal to no value, not even itself. To test
whether a number is NaN, you must use the isNaN method.

public static booleanisNaN(float val)

Returns true if val is a Not-a-Number (NaN) value.

public static booleanisInfinite(float val)

Returns true if val is either positive or negative infinity.

public booleanisNaN()

Returns true if this object's value is a Not-a-Number (NaN) value.

public booleanisInfinite()

Returns true if this object's value is either positive or negative infinity.

In addition to the usual constructor forms, Float has a constructor that takes a double argument to use as
its initial value after conversion to float.


Comparison of Float and Double objects behaves differently than float and double values. Each
wrapper class defines a sorting order that treats 0 less than +0, NaNs greater than all values (including + ),
and all NaNs equal to each other.

Free download pdf