Category: Language-Data types
Superclass: Number
I represent rational numbers in the form (p/q) where p and q are integers. The arithmetic operations *, +, -, /, on fractions, all return a reduced fraction.

Method category index

converting (class)
instance creation (class)
accessing (instance)
arithmetic (instance)
coercing (instance)
coercion (instance)
comparing (instance)
converting (instance)
optimized cases (instance)
printing (instance)
testing (instance)

converting (class)

coerce: aNumber
Answer aNumber converted to a Fraction

top


instance creation (class)

initialize
Initialize the receiver's class variables

numerator: nInteger denominator: dInteger

Answer a new instance of fraction (nInteger/dInteger)

top


accessing (instance)

denominator
Answer the receiver's denominator

numerator

Answer the receiver's numerator

top


arithmetic (instance)

* aNumber
Multiply two numbers and answer the result.

+ aNumber

Sum two numbers and answer the result.

- aNumber

Subtract aNumber from the receiver and answer the result.

/ aNumber

Divide the receiver by aNumber and answer the result.

// aNumber

Return the integer quotient of dividing the receiver by aNumber with truncation towards negative infinity.

\\ aNumber

Return the remainder from dividing the receiver by aNumber, (using //).

estimatedLog

Answer an estimate of (self abs floorLog: 10)

top


coercing (instance)

ceiling
Truncate the receiver towards positive infinity and return the truncated result

coerce: aNumber

Coerce aNumber to the receiver's class

floor

Truncate the receiver towards negative infinity and return the truncated result

generality

Return the receiver's generality

truncated

Truncate the receiver and return the truncated result

unity

Coerce 1 to the receiver's class

zero

Coerce 0 to the receiver's class

top


coercion (instance)

asCNumber
Convert the receiver to a kind of number that is understood by the C call-out mechanism.

top


comparing (instance)

< arg
Test if the receiver is less than arg.

<= arg

Test if the receiver is less than or equal to arg.

= arg

Test if the receiver equals arg.

> arg

Test if the receiver is more than arg.

>= arg

Test if the receiver is greater than or equal to arg.

hash

Answer an hash value for the receiver

top


converting (instance)

asExactFraction
Answer the receiver, it is already a Fraction

asFloatD

Answer the receiver converted to a FloatD

asFloatE

Answer the receiver converted to a FloatD

asFloatQ

Answer the receiver converted to a FloatD

asFraction

Answer the receiver, it is already a Fraction

integerPart

Answer the integer part of the receiver, expressed as a Fraction

top


optimized cases (instance)

negated
Return the receiver, with its sign changed.

raisedToInteger: anInteger

Return self raised to the anInteger-th power.

reciprocal

Return the reciprocal of the receiver

sqrt

Return the square root of the receiver.

squared

Return the square of the receiver.

top


printing (instance)

printOn: aStream
Print a representation of the receiver on aStream

storeOn: aStream

Store Smalltalk code compiling to the receiver on aStream

top


testing (instance)

isRational
Answer whether the receiver is rational - true

top