Squeak Class Documentation category index | class index  
 
Fraction
  category: Kernel-Numbers
  superclass: Number
  subclasses:

I represent some rational number as a fraction. All public arithmetic operations answer reduced fractions.

instance methods
  arithmetic
  *
+
-
/
negated
reciprocal

  comparing
  <
=
hash

  converting
  adaptToInteger:andSend:
asFloat
asFraction
isFraction

  mathematical functions
  raisedToInteger:
squared

  printing
  printOn:

  private
  denominator
numerator
reduced
setNumerator:denominator:

  truncation and round off
  truncated

class methods
  instance creation
  numerator:denominator:

instance methods
  arithmetic top  
 

*

Answer the result of multiplying the receiver by aNumber.


 

+

Answer the sum of the receiver and aNumber.


 

-

Answer the difference between the receiver and aNumber.


 

/

Answer the result of dividing the receiver by aNumber.


 

negated

Refer to the comment in Number|negated.


 

reciprocal

Refer to the comment in Number|reciprocal.


  comparing top  
 

<

Answer whether the receiver is less than the argument.


 

=

Compare the receiver with the argument and answer with true if the
receiver is equal to the argument. Otherwise answer false.


 

hash

Hash is reimplemented because = is implemented.


  converting top  
 

adaptToInteger:andSend:

If I am involved in arithmetic with an Integer, convert it to a Fraction.


 

asFloat

Answer a Float that closely approximates the value of the receiver.
Ideally, answer the Float that most closely approximates the receiver.


 

asFraction

Answer the receiver itself.


 

isFraction

Answer true if the receiver is a Fraction.


  mathematical functions top  
 

raisedToInteger:

See Number | raisedToInteger:


 

squared

See Fraction (Number) | squared


  printing top  
 

printOn:

Default print radix is 10


  private top  
 

denominator


 

numerator


 

reduced


 

setNumerator:denominator:


  truncation and round off top  
 

truncated

Refer to the comment in Number|truncated.


class methods
  instance creation top  
 

numerator:denominator:

Answer an instance of me (numInteger/denInteger).
NOTE: This primitive initialization method will not reduce improper fractions,
so normal usage should be coded as, eg,
(Fraction numerator: a denominator: b) reduced
or, more simply, as
a / b.