j2meClient.J2MEFloat Class Reference

A software implementation of IEEE-754 double precision math which does not rely on the float data type. More...


Public Member Functions

boolean equals (Object obj)
 Compares this object against the specified object.
int floatValue ()
 Returns the float value of this J2MEFloat object.
int hashCode ()
 Returns a hash code for this J2MEFloat object.
 J2MEFloat (String s)
 Constructs a newly-allocated J2MEFloat object that represents the argument.
 J2MEFloat (int f)
 Constructs a newly-allocated J2MEFloat object that represents the argument.
String toString ()
 Returns a String object representing this J2MEFloat's value.

Static Public Member Functions

static int abs (int f)
 Mimics Math.abs(float).
static int add (int f1, int f2)
 Returns the sum of the two float arguments according to section 15.18.2 of the JLS.
static byte byteValue (int f)
 Convert the given float to a byte as would happen in a casting operation specified by section 5.1.3 of the JLS.
static int ceil (int f)
 Mimics Math.ceil(double), using single precision.
static int compare (int f1, int f2)
 Mimics Float.compare(float, float).
static int div (int f1, int f2)
 Returns the quotient of the two float arguments according to section 15.17.2 of the JLS.
static int doubleToFloat (long d)
 Convert the given double to a float as would happen in a casting operation specified by section 5.1.3 of the JLS.
static long doubleValue (int f)
 Convert the given float to a double as would happen in a casting operation specified by section 5.1.2 of the JLS.
static boolean eq (int f1, int f2)
 Returns true if the specified numbers are considered equal according to section 15.21.1 of the JLS.
static int floor (int f)
 Mimics Math.floor(double), using single precision.
static boolean ge (int f1, int f2)
 Returns true if the first argument is considered greater than or equal to the second argument according to section 15.20.1 of the JLS.
static boolean gt (int f1, int f2)
 Returns true if the first argument is considered greater than the second argument according to section 15.20.1 of the JLS.
static int intToFloat (int x)
 Convert the given int to a float as would happen in a casting operation specified by section 5.1.2 of the JLS.
static int intValue (int f)
 Convert the given float to an int as would happen in a casting operation specified by section 5.1.3 of the JLS.
static boolean isInfinite (int f)
 Mimics Float.isInfinite(float).
static boolean isNaN (int f)
 Mimics Float.isNaN(float).
static boolean isZero (int f)
 Returns true if the specified number has zero magnitude, false otherwise.
static boolean le (int f1, int f2)
 Returns true if the first argument is considered less than or equal to the second argument according to section 15.20.1 of the JLS.
static int longToFloat (long x)
 Convert the given long to a float as would happen in a casting operation specified by section 5.1.2 of the JLS.
static long longValue (int f)
 Convert the given float to a long as would happen in a casting operation specified by section 5.1.3 of the JLS.
static boolean lt (int f1, int f2)
 Returns true if the first argument is considered less than the second argument according to section 15.20.1 of the JLS.
static int max (int f1, int f2)
 Mimics Math.max(float, float).
static int min (int f1, int f2)
 Mimics Math.min(float, float).
static int mod (int f1, int f2)
 Returns the remainder of the two float arguments according to section 15.17.3 of the JLS.
static int mul (int f1, int f2)
 Returns the product of the two float arguments according to section 15.17.1 of the JLS.
static boolean ne (int f1, int f2)
 Returns true if the specified numbers are considered unequal according to section 15.21.1 of the JLS.
static int negate (int f)
 Returns the negation of a float value.
static int parseFloat (String s)
 Mimics Float.parseFloat(String).
static int rint (int f)
 Mimics Math.rint(double), using single precision.
static int round (int f)
 Mimics Math.round(double), using single precision.
static short shortValue (int f)
 Convert the given float to a short as would happen in a casting operation specified by section 5.1.3 of the JLS.
static int sub (int f1, int f2)
 Returns the difference of the two float arguments according to section 15.18.2 of the JLS.
static String toString (int f)
 Mimics Float.toString(float).
static int truncate (int f)
 Returns the float of greatest magnitude (furthest from zero) that is equal to a mathematical integer and which has a mignitude not greater than the argument's magnitude.

Static Public Attributes

static final int E = 0x402df854
 A single-precision version of.
static final int MAX_VALUE = 0x7f7fffff
 A constant holding the same value as Float.MAX_VALUE.
static final int MIN_VALUE = 0x00000001
 A constant holding the same value as Float.MIN_VALUE.
static final int NaN = 0x7fc00000
 A constant holding the same value as Float.NaN.
static final int NEGATIVE_INFINITY = 0xff800000
 A constant holding the same value as Float.NEGATIVE_INFINITY.
static final int NEGATIVE_ZERO = 0x80000000
 A constant holding the value of -0.0f.
static final int ONE = 0x3f800000
 A constant holding the value of 1.0f.
static final int ONE_HALF = 0x3f000000
 A constant holding the value of 0.5f.
static final int PI = 0x40490fdb
 A single-precision version of.
static final int POSITIVE_INFINITY = 0x7f800000
 A constant representing the same value as Float.POSITIVE_INFINITY.
static final int TWO = 0x40000000
 A constant holding the value of 2.0f.
static final int ZERO = 0x00000000
 A constant holding the value of 0.0f.

Static Package Functions

static int pack (boolean negative, int exponent, long mantissa)
static int pack (boolean negative, int exponent, int mantissa)
static int unpackExponent (int f)
static int unpackMantissa (int f)
static boolean unpackSign (int f)

Detailed Description

A software implementation of IEEE-754 double precision math which does not rely on the float data type.

This class overloads the int data type by storing float data in it.

See also:
Float

Math

J2MEDouble

Version:
Revision
1.5

Constructor & Destructor Documentation

j2meClient.J2MEFloat.J2MEFloat ( int  f  ) 

Constructs a newly-allocated J2MEFloat object that represents the argument.

Parameters:
f the float value to be represented by the J2MEFloat.

j2meClient.J2MEFloat.J2MEFloat ( String  s  ) 

Constructs a newly-allocated J2MEFloat object that represents the argument.

Parameters:
s a String to be converted to a J2MEFloat.
Exceptions:
NumberFormatException if the String does not contain a parsable number.
See also:
parseFloat(String)


Member Function Documentation

static int j2meClient.J2MEFloat.add ( int  f1,
int  f2 
) [static]

Returns the sum of the two float arguments according to section 15.18.2 of the JLS.

This method takes the place of the binary + operator.

Parameters:
f1 the first float value to be summed.
f2 the second float value to be summed.
Returns:
the sum of the two arguments

static byte j2meClient.J2MEFloat.byteValue ( int  f  )  [static]

Convert the given float to a byte as would happen in a casting operation specified by section 5.1.3 of the JLS.

This is a narrowing primitive conversion which may result in a loss of magnitude and/or precision.

Note that this is a non-intuitive conversion. If the argument is outside of the range of the byte type, the result is basically meaningless.

Parameters:
f the float to be converted
Returns:
the byte representation of the argument

static int j2meClient.J2MEFloat.compare ( int  f1,
int  f2 
) [static]

Mimics Float.compare(float, float).

Note that when using this method (as well as Float.compare), the following rules apply:

  • NaN is considered to be equal to itself and greater than all other float values (including POSITIVE_INFINITY).
  • 0.0 is considered to be greater than -0.0.

static int j2meClient.J2MEFloat.div ( int  f1,
int  f2 
) [static]

Returns the quotient of the two float arguments according to section 15.17.2 of the JLS.

This method takes the place of the / operator.

Parameters:
f1 the float dividend
f2 the float divisor
Returns:
the quotient of the two arguments

static int j2meClient.J2MEFloat.doubleToFloat ( long  d  )  [static]

Convert the given double to a float as would happen in a casting operation specified by section 5.1.3 of the JLS.

This is a narrowing primitive conversion which may result in a loss of magnitude and/or precision.

Parameters:
d the double to be converted
Returns:
the float representation of the argument

static long j2meClient.J2MEFloat.doubleValue ( int  f  )  [static]

Convert the given float to a double as would happen in a casting operation specified by section 5.1.2 of the JLS.

This is a widening primitive conversion which will result in neither a loss of magnitude nor precision.

Parameters:
f the float to be converted
Returns:
the double representation of the argument

static boolean j2meClient.J2MEFloat.eq ( int  f1,
int  f2 
) [static]

Returns true if the specified numbers are considered equal according to section 15.21.1 of the JLS.

Special cases:

  • If either operand is NaN, then the result is false
  • Positive zero and negative zero are considered equal

This method takes the place of the == operator.

Parameters:
f1 the first float value to be compared.
f2 the second float value to be compared.
Returns:
true if the two values are considered equal; false otherwise.

boolean j2meClient.J2MEFloat.equals ( Object  obj  ) 

Compares this object against the specified object.

Equivalent to ((obj instanceof J2MEFloat) && (compare(((J2MEFloat) obj).floatValue(), floatValue()) == 0))

See also:
compare(int, int)

static boolean j2meClient.J2MEFloat.ge ( int  f1,
int  f2 
) [static]

Returns true if the first argument is considered greater than or equal to the second argument according to section 15.20.1 of the JLS.

Special cases:

  • If either operand is NaN, then the result is false
  • Positive zero and negative zero are considered equal
  • Negative infinity is conisdered less than all other values except NaN
  • Positive infinity is conisdered greater than all other values except NaN

This method takes the place of the >= operator.

Parameters:
f1 the first float value to be compared.
f2 the second float value to be compared.
Returns:
true if the first value is greater than or equal to the second value; false otherwise.

static boolean j2meClient.J2MEFloat.gt ( int  f1,
int  f2 
) [static]

Returns true if the first argument is considered greater than the second argument according to section 15.20.1 of the JLS.

Special cases:

  • If either operand is NaN, then the result is false
  • Positive zero and negative zero are considered equal
  • Negative infinity is conisdered less than all other values except NaN
  • Positive infinity is conisdered greater than all other values except NaN

This method takes the place of the > operator.

Parameters:
f1 the first float value to be compared.
f2 the second float value to be compared.
Returns:
true if the first value is greater than the second value; false otherwise.

int j2meClient.J2MEFloat.hashCode (  ) 

Returns a hash code for this J2MEFloat object.

Equivalent to floatValue().

static int j2meClient.J2MEFloat.intToFloat ( int  x  )  [static]

Convert the given int to a float as would happen in a casting operation specified by section 5.1.2 of the JLS.

This is a widening primitive conversion which will not result in a loss of magnitude, but might result in a loss of precision.

Parameters:
x the int to be converted
Returns:
the float representation of the argument

static int j2meClient.J2MEFloat.intValue ( int  f  )  [static]

Convert the given float to an int as would happen in a casting operation specified by section 5.1.3 of the JLS.

This is a narrowing primitive conversion which may result in a loss of magnitude and/or precision.

Parameters:
f the float to be converted
Returns:
the int representation of the argument

static boolean j2meClient.J2MEFloat.isZero ( int  f  )  [static]

Returns true if the specified number has zero magnitude, false otherwise.

Parameters:
f the float value to be tested.
Returns:
true if the value of the argument is positive zero or negative zero; false otherwise.

static boolean j2meClient.J2MEFloat.le ( int  f1,
int  f2 
) [static]

Returns true if the first argument is considered less than or equal to the second argument according to section 15.20.1 of the JLS.

Special cases:

  • If either operand is NaN, then the result is false
  • Positive zero and negative zero are considered equal
  • Negative infinity is conisdered less than all other values except NaN
  • Positive infinity is conisdered greater than all other values except NaN

This method takes the place of the <= operator.

Parameters:
f1 the first float value to be compared.
f2 the second float value to be compared.
Returns:
true if the first value is less than or equal to the second value; false otherwise.

static int j2meClient.J2MEFloat.longToFloat ( long  x  )  [static]

Convert the given long to a float as would happen in a casting operation specified by section 5.1.2 of the JLS.

This is a widening primitive conversion which will not result in a loss of magnitude, but might result in a loss of precision.

Parameters:
x the long to be converted
Returns:
the float representation of the argument

static long j2meClient.J2MEFloat.longValue ( int  f  )  [static]

Convert the given float to a long as would happen in a casting operation specified by section 5.1.3 of the JLS.

This is a narrowing primitive conversion which may result in a loss of magnitude and/or precision.

Parameters:
f the float to be converted
Returns:
the long representation of the argument

static boolean j2meClient.J2MEFloat.lt ( int  f1,
int  f2 
) [static]

Returns true if the first argument is considered less than the second argument according to section 15.20.1 of the JLS.

Special cases:

  • If either operand is NaN, then the result is false
  • Positive zero and negative zero are considered equal
  • Negative infinity is conisdered less than all other values except NaN
  • Positive infinity is conisdered greater than all other values except NaN

This method takes the place of the < operator.

Parameters:
f1 the first float value to be compared.
f2 the second float value to be compared.
Returns:
true if the first value is less than the second value; false otherwise.

static int j2meClient.J2MEFloat.mod ( int  f1,
int  f2 
) [static]

Returns the remainder of the two float arguments according to section 15.17.3 of the JLS.

This method takes the place of the % operator.

Parameters:
f1 the float dividend
f2 the float divisor
Returns:
the remainder of the two arguments

static int j2meClient.J2MEFloat.mul ( int  f1,
int  f2 
) [static]

Returns the product of the two float arguments according to section 15.17.1 of the JLS.

This method takes the place of the * operator.

Parameters:
f1 the first float value
f2 the second float value
Returns:
the product of the two arguments

static boolean j2meClient.J2MEFloat.ne ( int  f1,
int  f2 
) [static]

Returns true if the specified numbers are considered unequal according to section 15.21.1 of the JLS.

Special cases:

  • If either operand is NaN, then the result is true
  • Positive zero and negative zero are considered equal
The value returned by ne is always the opposite of the value returned by eq for the same arguments.

This method takes the place of the != operator.

Parameters:
f1 the first float value to be compared.
f2 the second float value to be compared.
Returns:
true if the two values are considered equal; false otherwise.

static int j2meClient.J2MEFloat.negate ( int  f  )  [static]

Returns the negation of a float value.

Special cases:

  • If the argument is negative zero, the result is positive zero.
  • If the argument is positive zero, the result is negative zero.
  • If the argument is negative infinity, the result is positive infinity.
  • If the argument is positive infinity, the result is negative infinity.
  • If the argument is NaN, the result is NaN.

This method takes the place of the unary - operator.

Parameters:
f the float value whose negated value is to be determined
Returns:
the negation of the argument.

static int j2meClient.J2MEFloat.pack ( boolean  negative,
int  exponent,
long  mantissa 
) [static, package]

Returns:
the float which most closely represents the given base-2 mantissa and exponent

static int j2meClient.J2MEFloat.pack ( boolean  negative,
int  exponent,
int  mantissa 
) [static, package]

Returns:
the float which most closely represents the given base-2 mantissa and exponent

static int j2meClient.J2MEFloat.parseFloat ( String  s  )  [static]

Mimics Float.parseFloat(String).

This implementation is known to be inaccurate, and does not always return the same value as Float.parseFloat. However the difference should be no greater than 1 ulp.

Exceptions:
NumberFormatException if the string does not contain a parsable number.

static short j2meClient.J2MEFloat.shortValue ( int  f  )  [static]

Convert the given float to a short as would happen in a casting operation specified by section 5.1.3 of the JLS.

This is a narrowing primitive conversion which may result in a loss of magnitude and/or precision.

Note that this is a non-intuitive conversion. If the argument is outside of the range of the short type, the result is basically meaningless.

Parameters:
f the float to be converted
Returns:
the short representation of the argument

static int j2meClient.J2MEFloat.sub ( int  f1,
int  f2 
) [static]

Returns the difference of the two float arguments according to section 15.18.2 of the JLS.

This method takes the place of the binary - operator.

Parameters:
f1 the first float value
f2 the second float value
Returns:
the difference of the two arguments

String j2meClient.J2MEFloat.toString (  ) 

Returns a String object representing this J2MEFloat's value.

Equivalent to toString(floatValue()).

See also:
toString(int)

static String j2meClient.J2MEFloat.toString ( int  f  )  [static]

Mimics Float.toString(float).

This implementation is known to be inaccurate, and does not always return the same value as Float.toString. However the difference should be no greater than 1 ulp.

static int j2meClient.J2MEFloat.truncate ( int  f  )  [static]

Returns the float of greatest magnitude (furthest from zero) that is equal to a mathematical integer and which has a mignitude not greater than the argument's magnitude.

Special cases:

  • If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

Parameters:
f a float value.
Returns:
the float of greatest magnitude (furthest from zero) whose magnitude is not greater than the argument's and which is equal to a mathematical integer.

static int j2meClient.J2MEFloat.unpackExponent ( int  f  )  [static, package]

Returns:
an integer in the range [-150, 105]

static int j2meClient.J2MEFloat.unpackMantissa ( int  f  )  [static, package]

Returns:
an integer in the range [0, 0x00ffffff]

static boolean j2meClient.J2MEFloat.unpackSign ( int  f  )  [static, package]

Returns:
true iff d is negative