Class BigFraction
java.lang.Object
BigFraction
- All Implemented Interfaces:
Comparable<BigFraction>
This is a a class of immutible extended-precision rational
numbers. All BigFractions are fully reduced and any
negative is in the numerator.
-
Field Summary
Modifier and TypeFieldDescriptionstatic BigFraction
This is the BigFraction 1/2.static BigFraction
This is the BigFraction 1/1.static BigFraction
This is the BigFraction 0/1. -
Constructor Summary
ConstructorDescriptionThis no-args constructor creates the BigFraction 0/1.BigFraction
(BigInteger num) This creates the BigFraction num/1.BigFraction
(BigInteger num, BigInteger denom) This is a general-purpose constructor that creates a BigFraction from a specified numerator denominator. -
Method Summary
Modifier and TypeMethodDescriptionadd
(BigFraction that) This computes the sum of two BigFractions.int
compareTo
(BigFraction that) This compares this BigFraction to the BigFraction that.divide
(BigFraction that) This computes the quotient of two BigFractions.boolean
This returns true when o is a BigFraction numerically equal to this BigFraction.static void
Test code goes in heremultiply
(BigFraction that) This computes the product of two BigFractions.pow
(int n) This computes thisn.subtract
(BigFraction that) This computes the difference of two BigFractions.toString()
This gives a string representation of the form num/denom.static BigFraction
valueOf
(long num, long denom) This static factory method produces a BigFraction with specified numerator and denominator that are longs.
-
Field Details
-
ONE
This is the BigFraction 1/1. -
ZERO
This is the BigFraction 0/1. -
HALF
This is the BigFraction 1/2.
-
-
Constructor Details
-
BigFraction
This is a general-purpose constructor that creates a BigFraction from a specified numerator denominator.- Parameters:
num
- the numerator of this BigFractiondenom
- the denominator of this BigFraction- Throws:
IllegalArgumentException
- if a zero denominator is provided.
-
BigFraction
This creates the BigFraction num/1.- Parameters:
num
- the numerator of this BigFraction. The denominator will be 1.
-
BigFraction
public BigFraction()This no-args constructor creates the BigFraction 0/1.
-
-
Method Details
-
valueOf
This static factory method produces a BigFraction with specified numerator and denominator that are longs.- Parameters:
num
- the numeratordenom
- the denominator- Returns:
- the BigFraction num/denom
-
toString
This gives a string representation of the form num/denom. -
equals
This returns true when o is a BigFraction numerically equal to this BigFraction. -
compareTo
This compares this BigFraction to the BigFraction that.- Specified by:
compareTo
in interfaceComparable<BigFraction>
- Parameters:
that
- the BigFraction we are comparing this BigFraction to.- Returns:
- a negative integer if this < that and a positive integer if this > that, and zero otherwise.
-
add
This computes the sum of two BigFractions.- Parameters:
that
- the BigFraction we are adding this BigFraction to.- Returns:
- this + that as a BigFraction.
-
subtract
This computes the difference of two BigFractions.- Parameters:
that
- the BigFraction we are subtraction from this BigFraction.- Returns:
- this - that as a BigFraction.
-
multiply
This computes the product of two BigFractions.- Parameters:
that
- the BigFraction we are multiplying by. this BigFraction.- Returns:
- this*that as a BigFraction.
-
divide
This computes the quotient of two BigFractions.- Parameters:
that
- the BigFraction we are dividing by. this BigFraction.- Returns:
- this/that as a BigFraction.
-
pow
This computes thisn.- Parameters:
n
- the power we are raising this BigFraction to.- Returns:
- thisn
-
main
Test code goes in here- Parameters:
args
- command-line arguments
-