org.erights.e.meta.java.lang
Class DoubleSugar

java.lang.Object
  |
  +--org.erights.e.meta.java.lang.DoubleSugar

public class DoubleSugar
extends Object

Untamed: A sweetener defining extra messages that may be e-sent to a floating point number.

Author:
Mark S. Miller

Field Summary
private static double AfterMinus3
           
private static long Minus3Bits
          Detect whether this jvm has a known bug in reporting floating point representation.
private static boolean NegRepBug
           
 
Constructor Summary
private DoubleSugar()
          prevent instantiation
 
Method Summary
static boolean aboveZero(double self)
          Enabled: Used in the expansion of E's ">" operator.
static double abs(double num)
          Enabled:
static double acos(double self)
          Enabled:
static double add(double self, double arg)
          Enabled:
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 double asin(double self)
          Enabled:
static double atan(double self)
          Enabled:
static double atan2(double self, double arg)
          Enabled:
static boolean atLeastZero(double self)
          Enabled: Used in the expansion of E's ">=" operator.
static boolean atMostZero(double self)
          Enabled: Used in the expansion of E's "<=" operator.
static boolean belowZero(double self)
          Enabled: Used in the expansion of E's "<" operator.
static BigInteger ceil(double self)
          Enabled:
static double compareTo(double self, Object o)
          Enabled: Used in the expansion of E's comparison operators.
static double cos(double self)
          Enabled:
static double exp(double self)
          Enabled:
static BigInteger floor(double self)
          Enabled:
static BigInteger floorDivide(double self, double arg)
          Enabled: Always gives an integer, resulting from rounding towards negative infinity, ie, flooring.
static boolean isZero(double self)
          Enabled: Used for arithmetic equality.
static double log(double self)
          Enabled:
static double max(double self, double arg)
          Enabled:
static double min(double self, double arg)
          Enabled:
static double mod(double self, double arg)
          Enabled: Remainder from the floorDivide operation.
static double modPow(double self, double exp, double modulus)
          Enabled:
static double multiply(double self, double arg)
          Enabled:
static double negate(double self)
          Enabled:
static double next(double self)
          Enabled: Infinity.next() == Infinity
static double pow(double self, double arg)
          Enabled:
static double previous(double self)
          Enabled: (-Infinity).previous() == -Infinity
static double random(double self)
          Enabled: A number randomly chosen between 0 and this number.
static double remainder(double self, double arg)
          Enabled: Remainder from truncDivide operation.
static BigInteger round(double self)
          Enabled:
static double sin(double self)
          Enabled:
static double sqrt(double self)
          Enabled:
static double subtract(double self, double arg)
          Enabled:
static double tan(double self)
          Enabled:
static BigInteger truncate(double self)
          Enabled:
static long truncDivide(double self, double 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

Minus3Bits

private static final long Minus3Bits
Detect whether this jvm has a known bug in reporting floating point representation.


AfterMinus3

private static final double AfterMinus3

NegRepBug

private static final boolean NegRepBug
Constructor Detail

DoubleSugar

private DoubleSugar()
prevent instantiation

Method Detail

aboveZero

public static boolean aboveZero(double self)
Enabled: Used in the expansion of E's ">" operator. NaN says false


abs

public static double abs(double num)
Enabled:


acos

public static double acos(double self)
Enabled:


add

public static double add(double self,
                         double arg)
Enabled:


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.


asin

public static double asin(double self)
Enabled:


atan

public static double atan(double self)
Enabled:


atan2

public static double atan2(double self,
                           double arg)
Enabled:


atLeastZero

public static boolean atLeastZero(double self)
Enabled: Used in the expansion of E's ">=" operator. NaN says false


atMostZero

public static boolean atMostZero(double self)
Enabled: Used in the expansion of E's "<=" operator. NaN says false


belowZero

public static boolean belowZero(double self)
Enabled: Used in the expansion of E's "<" operator. NaN says false


ceil

public static BigInteger ceil(double self)
Enabled:


compareTo

public static double compareTo(double self,
                               Object o)
Enabled: Used in the expansion of E's comparison operators. As is Java, is E, NaNs are incomparable to everything else, and so yield a NaN as an answer.


cos

public static double cos(double self)
Enabled:


exp

public static double exp(double self)
Enabled:


floor

public static BigInteger floor(double self)
Enabled:


floorDivide

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


isZero

public static boolean isZero(double self)
Enabled: Used for arithmetic equality. NaN says false


log

public static double log(double self)
Enabled:


max

public static double max(double self,
                         double arg)
Enabled:


min

public static double min(double self,
                         double arg)
Enabled:


mod

public static double mod(double self,
                         double 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().


modPow

public static double modPow(double self,
                            double exp,
                            double modulus)
Enabled:


multiply

public static double multiply(double self,
                              double arg)
Enabled:


negate

public static double negate(double self)
Enabled:


pow

public static double pow(double self,
                         double arg)
Enabled:


random

public static double random(double self)
Enabled: A number randomly chosen between 0 and this number. Only as good as Math.random(), which it uses.


remainder

public static double remainder(double self,
                               double arg)
Enabled: Remainder from 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.


round

public static BigInteger round(double self)
Enabled:


sin

public static double sin(double self)
Enabled:


sqrt

public static double sqrt(double self)
Enabled:


subtract

public static double subtract(double self,
                              double arg)
Enabled:


tan

public static double tan(double self)
Enabled:


truncate

public static BigInteger truncate(double self)
Enabled:


truncDivide

public static long truncDivide(double self,
                               double arg)
Enabled: Always gives an integer resulting from rounding towards zero, ie, truncating. This corresponds to the Java integer "/" operator.


next

public static double next(double self)
Enabled: Infinity.next() == Infinity

NaN.next() == NaN

Double.getMAX_VALUE().next() == Infinity

(-Infinity).next() == -(Double.getMAX_VALUE())

otherwise, *num*.next() == *next representable number*


previous

public static double previous(double self)
Enabled: (-Infinity).previous() == -Infinity

NaN.previous() == NaN

-(Double.getMAX_VALUE()).previous() == -Infinity

Infinity.previous() == Double.getMAX_VALUE()

otherwise, *num*.previous() == *previous representable number*



comments?