Back: FloatQ-converting Up: Base classes Forward: Fraction class-converting   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document

1.82 Fraction

Defined in namespace Smalltalk
Superclass: Number
Category: Language-Data types
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.

1.82.1 Fraction class: converting  (class)
1.82.2 Fraction class: instance creation  (class)
1.82.3 Fraction: accessing  (instance)
1.82.4 Fraction: arithmetic  (instance)
1.82.5 Fraction: coercing  (instance)
1.82.6 Fraction: coercion  (instance)
1.82.7 Fraction: comparing  (instance)
1.82.8 Fraction: converting  (instance)
1.82.9 Fraction: optimized cases  (instance)
1.82.10 Fraction: printing  (instance)
1.82.11 Fraction: testing  (instance)


1.82.1 Fraction class: converting

coerce: aNumber
Answer aNumber converted to a Fraction


1.82.2 Fraction class: instance creation

initialize
Initialize the receiver's class variables

numerator: nInteger denominator: dInteger
Answer a new instance of fraction (nInteger/dInteger)


1.82.3 Fraction: accessing

denominator
Answer the receiver's denominator

numerator
Answer the receiver's numerator


1.82.4 Fraction: arithmetic

* 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)


1.82.5 Fraction: coercing

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


1.82.6 Fraction: coercion

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


1.82.7 Fraction: comparing

< 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


1.82.8 Fraction: converting

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


1.82.9 Fraction: optimized cases

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.


1.82.10 Fraction: printing

printOn: aStream
Print a representation of the receiver on aStream

storeOn: aStream
Store Smalltalk code compiling to the receiver on aStream


1.82.11 Fraction: testing

isRational
Answer whether the receiver is rational - true



Back: Fraction-printing Up: Fraction Forward: Generator   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document


This document was generated on February, 22 2012 using texi2html