org.erights.e.meta.java.math
Class BigIntegerSugar

java.lang.Object
  |
  +--org.erights.e.meta.java.math.BigIntegerSugar

public class BigIntegerSugar
extends Object

Untamed: A sweetener defining extra messages that may be e-sent to an integer.

Author:
Mark S. Miller

Field Summary
(package private) static String BASE64
           
 
Constructor Summary
private BigIntegerSugar()
          prevent instantiation
 
Method Summary
static boolean aboveZero(BigInteger self)
          Enabled: Used in the expansion of E's ">" operator
static double approxDivide(double self, double arg)
          Enabled: Always gives back a Double This corresponds to the Java floating-point "/" operator and the E "/" operator.
static char asChar(BigInteger self)
          Enabled: Returns the Unicode character with this character code.
static double asFloat64(double self)
          Enabled: Returns the "best" IEEE double precision floating point equivalent to this number.
static boolean atLeastZero(BigInteger self)
          Enabled: Used in the expansion of E's ">=" operator
static boolean atMostZero(BigInteger self)
          Enabled: Used in the expansion of E's "<=" operator
static boolean belowZero(BigInteger self)
          Enabled: Used in the expansion of E's "<" operator
static BigInteger butNot(BigInteger self, BigInteger arg)
          Enabled: In E, andNot() is called butNot()
static BigInteger ceil(BigInteger self)
          Enabled: Defined both here and in DoubleSugar, so you can use this to get a ceil'ed integer no matter what kind of number you start with.
static int compareTo(BigInteger self, Object o)
          Enabled: Overrides the inherited 'compareTo' to coerce 'o' to a BigInteger
static BigInteger complement(BigInteger val)
          Deprecated. Use BigInteger.not() instead.
static BigInteger cryptoHash(BigInteger self)
          Enabled: Actually, a SHA hash
static BigInteger floor(BigInteger self)
          Enabled: Defined both here and in DoubleSugar, so you can use this to get a floor'ed integer no matter what kind of number you start with.
static BigInteger floorDivide(BigInteger self, BigInteger arg)
          Enabled: Always gives an integer, resulting from rounding towards negative infinity, ie, flooring.
static boolean isNaN(BigInteger self)
          Enabled: All integers are numbers, so this is always false
static boolean isZero(BigInteger self)
          Enabled: Used for arithmetic equality
static BigInteger mod(BigInteger self, BigInteger arg)
          Enabled: Remainder from the floorDivide operation.
static BigInteger next(BigInteger self)
          Enabled: The next higher integer
static BigInteger previous(BigInteger self)
          Enabled: The next lower integer
static BigInteger round(BigInteger self)
          Enabled: Defined both here and in DoubleSugar, so you can use this to get round'ed integer no matter what kind of number you start with.
static String toString64(BigInteger self)
          Enabled: Convert an integer to a base 64 string, with an optional leading minus sign.
static BigInteger truncate(BigInteger self)
          Enabled: Defined both here and in DoubleSugar, so you can use this to get truncate'd integer no matter what kind of number you start with.
static BigInteger truncDivide(BigInteger self, BigInteger arg)
          Enabled: Always gives an integer resulting from rounding towards zero, ie, truncating.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASE64

static final String BASE64
Constructor Detail

BigIntegerSugar

private BigIntegerSugar()
prevent instantiation

Method Detail

approxDivide

public static double approxDivide(double self,
                                  double arg)
Enabled: Always gives back a Double This corresponds to the Java floating-point "/" operator and the E "/" operator.


asChar

public static char asChar(BigInteger self)
Enabled: Returns the Unicode character with this character code.


asFloat64

public static double asFloat64(double self)
Enabled: Returns the "best" IEEE double precision floating point equivalent to this number. If this number is representable in IEEE double precision, then that IEEE value is returned. Otherwise, convert by rounding to even.


aboveZero

public static boolean aboveZero(BigInteger self)
Enabled: Used in the expansion of E's ">" operator


atLeastZero

public static boolean atLeastZero(BigInteger self)
Enabled: Used in the expansion of E's ">=" operator


atMostZero

public static boolean atMostZero(BigInteger self)
Enabled: Used in the expansion of E's "<=" operator


belowZero

public static boolean belowZero(BigInteger self)
Enabled: Used in the expansion of E's "<" operator


isZero

public static boolean isZero(BigInteger self)
Enabled: Used for arithmetic equality


isNaN

public static boolean isNaN(BigInteger self)
Enabled: All integers are numbers, so this is always false


ceil

public static BigInteger ceil(BigInteger self)
Enabled: Defined both here and in DoubleSugar, so you can use this to get a ceil'ed integer no matter what kind of number you start with. Similarly, the "doubleValue" message will get you a floating point value no matter what you start with.


compareTo

public static int compareTo(BigInteger self,
                            Object o)
Enabled: Overrides the inherited 'compareTo' to coerce 'o' to a BigInteger


complement

public static BigInteger complement(BigInteger val)
Deprecated. Use BigInteger.not() instead.

Enabled: This method supports the C-tradition expectation that unary "~" will work as bit complement.

However, the E style, supported by other set-like abstractions, is to use unary "!" instead.


floor

public static BigInteger floor(BigInteger self)
Enabled: Defined both here and in DoubleSugar, so you can use this to get a floor'ed integer no matter what kind of number you start with. Similarly, the "doubleValue" message will get you a floating point value no matter what you start with.


floorDivide

public static BigInteger floorDivide(BigInteger self,
                                     BigInteger arg)
Enabled: Always gives an integer, resulting from rounding towards negative infinity, ie, flooring. This corresponds to the E "_/" operator.


butNot

public static BigInteger butNot(BigInteger self,
                                BigInteger arg)
Enabled: In E, andNot() is called butNot()


mod

public static BigInteger mod(BigInteger self,
                             BigInteger arg)
Enabled: Remainder from the floorDivide operation.

     (a floorDivide b)*b + (a modulo b) == a
      [ 5, 3]: ( 1* 3) +  2 ==  5
      [ 5,-3]: (-2*-3) + -1 ==  5
      [-5, 3]: (-2* 3) +  1 == -5
      [-5,-3]: ( 1*-3) + -2 == -5
 

Therefore, if the result is non-zero, the sign of the result must be the same as the sign of b, and so the result ranges from 0 inclusive to b exclusive. This corresponds to the E "%%" operator. When b >= 0, it also corresponds to Java's BigInteger.mod().


round

public static BigInteger round(BigInteger self)
Enabled: Defined both here and in DoubleSugar, so you can use this to get round'ed integer no matter what kind of number you start with. Similarly, the "doubleValue" message will get you a floating point value no matter what you start with.


truncate

public static BigInteger truncate(BigInteger self)
Enabled: Defined both here and in DoubleSugar, so you can use this to get truncate'd integer no matter what kind of number you start with. Similarly, the "doubleValue" message will get you a floating point value no matter what you start with.


truncDivide

public static BigInteger truncDivide(BigInteger self,
                                     BigInteger arg)
Enabled: Always gives an integer resulting from rounding towards zero, ie, truncating. This corresponds to the Java integer "/" operator. BigInteger's existing 'remainder' gives the correct remainder from the truncDivide operation.

      (a truncDivide b)*b + (a remainder b) == a
      [ 5, 3]: ( 1* 3) +  2 ==  5
      [ 5,-3]: (-1*-3) +  2 ==  5
      [-5, 3]: (-1* 3) + -2 == -5
      [-5,-3]: ( 1*-3) + -2 == -5
 

Therefore, if the result is non-zero, the sign of the result must be the same as the sign of a. This corresponds to the Java and E "%" operator.


next

public static BigInteger next(BigInteger self)
Enabled: The next higher integer


previous

public static BigInteger previous(BigInteger self)
Enabled: The next lower integer


toString64

public static String toString64(BigInteger self)
Enabled: Convert an integer to a base 64 string, with an optional leading minus sign.

A negative integer is encoded as a "-" followed by the encoding of the absolute magnitude. For a positive integer, the encoded length will be (4 * b.length)/3, rounded up to the next integral (non-fractional) character length.

Each base 64 digit is encoded by one of the characters


cryptoHash

public static BigInteger cryptoHash(BigInteger self)
Enabled: Actually, a SHA hash



comments?