net.jinx.slowmath
Interface Real

All Superinterfaces:
java.lang.Comparable
All Known Implementing Classes:
ADouble, AFloat

public interface Real
extends java.lang.Comparable

This interface provides a way to completely abstract mathematical operations, allowing you to swap data types in a program with very little work. There are currently only two implementations: ADouble and AFloat. In the future, there will be others. For example, a BigDecimal based implementation (if I can figure out how to handle forcing a precision level under 1.4.2). There are also plans in place to have a fixed-point based implementation.

This interfaces implementations are named the way they are because Double, Float, etc. are already taken by the java.lang package. I chose to add the A on the beginning, to represent that the implementing classes include arithmetic operations.

API Stability: Alpha; I may add a fixedPointValue() method, should I ever get around to implementing a fixed point library. The thing stopping me from doing this is the exponential and trigonometry methods.

I'm just as likely to re-implement this as an abstract class and give the typecasting operations concrete implementations.


Method Summary
 Real abs()
          Returns the absolute value of this Real.
 Real acos()
          Returns the arc cosine of this Real.
 Real add(Real v)
          Adds this and another Real together, returning the results.
 Real asin()
          Returns the arc sine of this Real.
 Real atan()
          Returns the arc tanget of this Real.
 java.math.BigDecimal bigDecimalValue()
          Type-casts to a BigDecimal.
 byte byteValue()
          Type-casts to a byte.
 int compareTo(java.lang.Object o)
          Compares this Real with o.
 int compareTo(Real v)
          Compares this Real with v.
 Real cos()
          Returns the cosine of this Real.
 Real divide(Real v)
          Divides this by another Real together, returning the results.
 double doubleValue()
          Type-casts to a double.
 Real exp()
          Returns Euler's number raised by this Real.
 float floatValue()
          Type-casts to a float.
 int intValue()
          Type-casts to an int.
 Real log()
          Returns the natural logarithm of this Real.
 long longValue()
          Type-casts to a long.
 Real max(Real v)
          Returns the maximum of this Real and another.
 Real min(Real v)
          Returns the minimum of this Real and another.
 Real multiply(Real v)
          Multiplies this and another Real together, returning the results.
 Real negate()
          Returns the negation of this Real.
 Real pow(Real v)
          Returns the power of this Real raised by another.
 short shortValue()
          Type-casts to a short.
 Real signum()
          Returns the signum of this Real.
 Real sin()
          Returns the sine of this Real.
 Real sqrt()
          Returns the square root of this Real.
 Real subtract(Real v)
          Subtracts another Real from this, returning the results.
 Real tan()
          Returns the tangent of this Real.
 java.lang.String toString()
          Type-casts to a String.
 

Method Detail

add

Real add(Real v)
Adds this and another Real together, returning the results.


subtract

Real subtract(Real v)
Subtracts another Real from this, returning the results.


multiply

Real multiply(Real v)
Multiplies this and another Real together, returning the results.


divide

Real divide(Real v)
Divides this by another Real together, returning the results.


abs

Real abs()
Returns the absolute value of this Real.


negate

Real negate()
Returns the negation of this Real.


signum

Real signum()
Returns the signum of this Real.


min

Real min(Real v)
Returns the minimum of this Real and another.


max

Real max(Real v)
Returns the maximum of this Real and another.


pow

Real pow(Real v)
Returns the power of this Real raised by another.


sqrt

Real sqrt()
Returns the square root of this Real.


log

Real log()
Returns the natural logarithm of this Real.


exp

Real exp()
Returns Euler's number raised by this Real.


sin

Real sin()
Returns the sine of this Real.


cos

Real cos()
Returns the cosine of this Real.


tan

Real tan()
Returns the tangent of this Real.


asin

Real asin()
Returns the arc sine of this Real.


acos

Real acos()
Returns the arc cosine of this Real.


atan

Real atan()
Returns the arc tanget of this Real.


byteValue

byte byteValue()
Type-casts to a byte.


shortValue

short shortValue()
Type-casts to a short.


intValue

int intValue()
Type-casts to an int.


longValue

long longValue()
Type-casts to a long.


floatValue

float floatValue()
Type-casts to a float.


doubleValue

double doubleValue()
Type-casts to a double.


bigDecimalValue

java.math.BigDecimal bigDecimalValue()
Type-casts to a BigDecimal.


toString

java.lang.String toString()
Type-casts to a String.

Overrides:
toString in class java.lang.Object

compareTo

int compareTo(java.lang.Object o)
Compares this Real with o. If o is a Real, this method behaves like compareTo(Real). Otherwise, it throws a ClassCastException, since Reals are comparable only to other Reals.

Specified by:
compareTo in interface java.lang.Comparable
Returns:
a negative number, zero, or a positive number as this Real is numerically less than, equal to, or greater than o, which must be a Real.
Throws:
java.lang.ClassCastException - if o isn't a Real.

compareTo

int compareTo(Real v)
Compares this Real with v.

Returns:
a negative number, zero, or a positive number as this Real is numerically less than, equal to, or greater than v.