Maturity Index:Relatively immature
+ totalFraction : aNumeratorReturns a new fraction with numerator set to aNumerator and denominator set to the element one for aNumerator.
numerator:denominator:
+ numerator : aNumerator denominator : aDenominator
Returns a new fraction with numerator set to aNumerator and denominator set to aDenominator. Don't forget to use cheapCopy if you want to keep the arguments in scope.
copy
- copy
Returns a new copy of the fraction; sends cheapCopy messages to denominator and numerator.
deepCopy
- deepCopy
Returns a new copy of the fraction; sends deepCopy messages to denominator and numerator.
clear
- clear
Sends free messages to denominator and numerator.
numerator
- numerator
Returns a for a fraction a/b. You may not modify or free the object returned by this method.
denominator
- denominator
Returns b for a fraction a/b. You may not modify or free the object returned by this method.
hash
- (unsigned) hash
Returns a small integer that is the same for fractions that are equal in the sense of isEqual:.
isEqual:
- (BOOL) isEqual : b
Two fractions are equal if they are pointer equal, or if their numerators and denominators are equal. If the numerators and denominators are coprime, but not ordered, the method returns YES if numerators and denominators are opposite to each other. If the fraction is not in canonical form, it is verified that the difference of the two fractions is zero.
compare:
- (int) compare : b
Compares the fractions by comparing the products of numerators and denominators.
asNumerical
- asNumerical
Returns the numerical value of the fraction. Attempts to divide the numerical value of the numerator and denominator.
asModp:
- asModp :(unsigned short) p
Returns the value of the fraction modulo p. Attempts to divide the values of the numerator and denominator. If the division fails, the method generates an error message.
asIntegral
- asIntegral
Returns, if the denominator of the fraction is equal to one, a new reference to the numerator. Otherwise, the method generates an error message.
zero
- zero
Returns a new fraction with numerator equal to zero.
isZero
- (BOOL) isZero
Whether the numerator of the fraction is equal to zero.
isOpposite:
- (BOOL) isOpposite : b
Two fractions are opposite if their numerators are opposite and the denominators are equal. However, if the numerators and denominators are coprime, but not ordered, the method returns YES if the numerators are equal and the denominators are opposite to each other. If the fraction is not in canonical form, it is verified that the sum of the two fractions is zero.
negate
- negate
Returns a new fraction, the opposite of self by negating the numerator.
double
- double
Returns a new fraction, the double of self by doubling the numerator.
add:
- add : b
Returns a new fraction, the sum of self and b. The method first handles some special cases and then distinguishes between the case that both fractions have a common denominator or not.
subtract:
- subtract : b
Returns a new fraction, the difference of self and b. The method first handles some special cases and then distinguishes between the case that both fractions have a common denominator or not.
one
- one
Returns a new fraction with numerator equal to one.
isOne
- (BOOL) isOne
Whether the numerator is equal to the denominator.
isMinusOne
- (BOOL) isMinusOne
Whether the numerator is the opposite of the denominator.
square
- square
Returns a new fraction; squares numerator and denominator.
inverse
- inverse
Returns the inverse of the fraction; interchanges, in the case of a total fraction, denominator and numerator.
multiply:
- multiply : b
Returns a new fraction; multiplies the numerators and the denominators together.
divide:
- divide : b
Returns a new fraction by multiplying the fraction by the inverse of b.
power:
- power :(int) n
Returns a new fraction; raises numerator and denominator to the n-th power.
intValue:
- intValue :(int) intValue
Creates a fraction with numerator equal to intValue and denominator one.
intValue
- (int) intValue
Returns intValue of numerator divided by intValue of denominator.
multiplyIntValue:
- multiplyIntValue :(int) intValue
Returns a new fraction by multiplying the numerator by intValue.
divideIntValue:
- divideIntValue :(int) intValue
Returns a new fraction by multiplying the denominator by intValue.
printsLeadingSign
- (BOOL) printsLeadingSign
Whether the fraction prints a leading minus sign.
printsSum
- (BOOL) printsSum
Whether the fraction prints as a sum.
printsProduct
- (BOOL) printsProduct
Whether the fraction prints as a product.