|
|
6.71 Fraction
- Defined in namespace Smalltalk
- 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.
6.71.1 Fraction class: converting
- coerce: aNumber
- Answer aNumber converted to a Fraction
6.71.2 Fraction class: instance creation
- initialize
- Initialize the receiver's class variables
- numerator: nInteger denominator: dInteger
- Answer a new instance of fraction (nInteger/dInteger)
6.71.3 Fraction: accessing
- denominator
- Answer the receiver's denominator
- numerator
- Answer the receiver's numerator
6.71.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)
6.71.5 Fraction: coercing
- coerce: aNumber
- Coerce aNumber to the receiver's class
- 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
6.71.6 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
6.71.7 Fraction: converting
- asFloat
- Answer the receiver converted to a Float
- asFraction
- Answer the receiver converted to a Fraction
6.71.8 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.
- squared
- Return the square of the receiver.
6.71.9 Fraction: printing
- printOn: aStream
- Print a representation of the receiver on aStream
- storeOn: aStream
- Store Smalltalk code compiling to the receiver on aStream
6.71.10 Fraction: testing
- isRational
- Answer whether the receiver is rational - true
|