Class MyNumbers

java.lang.Object
  |
  +--MyNumbers

class MyNumbers
extends java.lang.Object

Generic utility functions for MyNumbers.


Method Summary
static MyNumber abs(MyNumber n)
          Returns a new MyNumber object that initially holds the absolute value of n.
static boolean divides(MyNumber m0, MyNumber n0)
          Returns true if m divides n evenly.
static boolean isNegative(MyNumber n)
          Returns true if n is negative.
static boolean isZero(MyNumber n)
          Returns true if n is zero.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isZero

public static boolean isZero(MyNumber n)
Returns true if n is zero.
Parameters:
n - the number to test
Returns:
true if n is zero; false otherwise

isNegative

public static boolean isNegative(MyNumber n)
Returns true if n is negative.
Parameters:
n - the number to test
Returns:
true if n is less than zero; false otherwise

abs

public static MyNumber abs(MyNumber n)
Returns a new MyNumber object that initially holds the absolute value of n.

[The returned object is guaranteed to be an instance of n's class.]

Parameters:
n - the number whose is magnitude is to be taken
Returns:
a new MyNumber object whose initial value is the magnitude of n

divides

public static boolean divides(MyNumber m0,
                              MyNumber n0)
Returns true if m divides n evenly. When n and m are both positive, this is equivalent to saying that true is returned iff
  n = m + m + m + ... + m + m + m
where m may be repeated zero or more times on the right-hand side.

[For consistency with MyInteger, the divides method's behavior is undefined when m is zero.]

Parameters:
m - the number to divide by
n - the number to divide into
Returns:
true if m divides n evenly; false otherwise