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

I am an abstract representation of a number. My subclasses Float, Fraction, and Integer, and their subclasses, provide concrete representations of a numeric quantity.

All my subclasses participate in a simple type coercion mechanism that supports mixed-mode arithmetic and comparisons. It works as follows: If
self<typeA> op: arg<typeB>
fails because of incompatible types, then it is retried in the following guise:
(arg adaptTypeA: self) op: arg adaptToTypeA.
This gives the arg of typeB an opportunity to resolve the incompatibility, knowing exactly what two types are involved. If self is more general, then arg will be converted, and viceVersa. This mechanism is extensible to any new number classes that one might wish to add to Squeak. The only requirement is that every subclass of Number must support a pair of conversion methods specific to each of the other subclasses of Number.

instance methods
  arithmetic
  *
+
-
/
//
\\
abs
negated
quo:
reciprocal
rem:

  as yet unclassified
  reduce

  comparing
  closeTo:

  converting
  @
adaptToCollection:andSend:
adaptToFloat:andSend:
adaptToFraction:andSend:
adaptToInteger:andSend:
adaptToPoint:andSend:
adaptToString:andSend:
asB3DVector3
asInteger
asNumber
asPoint
asSmallAngleDegrees
asSmallPositiveDegrees
degreesToRadians
radiansToDegrees

  filter streaming
  byteEncode:

  intervals
  to:
to:by:
to:by:do:
to:do:

  mathematical functions
  arcCos
arcSin
arcTan
arcTan:
cos
exp
floorLog:
interpolateTo:at:
ln
log
log:
raisedTo:
raisedToInteger:
sin
sqrt
squared
tan

  printing
  defaultLabelForInspector
isOrAreStringWith:
newTileMorphRepresentative
printOn:
printStringBase:
storeOn:
storeOn:base:
storeStringBase:
stringForReadout

  testing
  basicType
even
isDivisibleBy:
isInf
isInfinite
isNaN
isNumber
isZero
negative
odd
positive
sign
strictlyPositive

  truncation and round off
  ceiling
detentBy:atMultiplesOf:snap:
floor
roundTo:
roundUpTo:
rounded
truncateTo:
truncated

  vocabulary
  vocabularyDemanded

class methods
  examples
  exampleFor:

  instance creation
  readFrom:
readFrom:base:
readRemainderOf:from:base:withSign:

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.


 

//

Integer quotient defined by division with truncation toward negative
infinity. 9//4 = 2, -9//4 = -3. -0.9//0.4 = -3. \\ answers the remainder
from this division.


 

\\

modulo. Remainder defined in terms of //. Answer a Number with the
same sign as aNumber. e.g. 9\\4 = 1, -9\\4 = 3, 9\\-4 = -3, 0.9\\0.4 = 0.1.


 

abs

Answer a Number that is the absolute value (positive magnitude) of the
receiver.


 

negated

Answer a Number that is the negation of the receiver.


 

quo:

Integer quotient defined by division with truncation toward zero. -9 quo:
4 = -2, -0.9 quo: 0.4 = -2. rem: answers the remainder from this division.


 

reciprocal

Answer 1 divided by the receiver. Create an error notification if the
receiver is 0.


 

rem:

Remainder defined in terms of quo:. Answer a Number with the same
sign as self. e.g. 9 rem: 4 = 1, -9 rem: 4 = -1. 0.9 rem: 0.4 = 0.1.


  as yet unclassified top  
 

reduce

If self is close to an integer, return that integer


  comparing top  
 

closeTo:

are these two numbers close?


  converting top  
 

@

Primitive. Answer a Point whose x value is the receiver and whose y
value is the argument. Optional. No Lookup. See Object documentation
whatIsAPrimitive.


 

adaptToCollection:andSend:

If I am involved in arithmetic with a Collection, return a Collection of
the results of each element combined with me in that expression.


 

adaptToFloat:andSend:

If I am involved in arithmetic with a Float, convert me to a Float.


 

adaptToFraction:andSend:

If I am involved in arithmetic with a Fraction, convert us and evaluate exprBlock.


 

adaptToInteger:andSend:

If I am involved in arithmetic with a Integer, convert us and evaluate exprBlock.


 

adaptToPoint:andSend:

If I am involved in arithmetic with a Point, convert me to a Point.


 

adaptToString:andSend:

If I am involved in arithmetic with a String, convert it to a Number.


 

asB3DVector3


 

asInteger

Answer an Integer nearest the receiver toward zero.


 

asNumber


 

asPoint

Answer a Point with the receiver as both coordinates; often used to
supply the same value in two dimensions, as with symmetrical gridding
or scaling.


 

asSmallAngleDegrees

Return the receiver normalized to lie within the range (-180, 180)


 

asSmallPositiveDegrees

Return the receiver normalized to lie within the range (0, 360)


 

degreesToRadians

The receiver is assumed to represent degrees. Answer the conversion to
radians.


 

radiansToDegrees

The receiver is assumed to represent radians. Answer the conversion to
degrees.


  filter streaming top  
 

byteEncode:


  intervals top  
 

to:

Answer an Interval from the receiver up to the argument, stop,
incrementing by 1.


 

to:by:

Answer an Interval from the receiver up to the argument, stop,
incrementing by step.


 

to:by:do:

Normally compiled in-line, and therefore not overridable.
Evaluate aBlock for each element of the interval (self to: stop by:
step).


 

to:do:

Normally compiled in-line, and therefore not overridable.
Evaluate aBlock for each element of the interval (self to: stop by: 1).


  mathematical functions top  
 

arcCos

The receiver is the cosine of an angle. Answer the angle measured in
radians.


 

arcSin

The receiver is the sine of an angle. Answer the angle measured in
radians.


 

arcTan

The receiver is the tangent of an angle. Answer the angle measured in
radians.


 

arcTan:

The receiver is the tangent of an angle. Answer the angle measured in
radians.


 

cos

The receiver represents an angle measured in radians. Answer its cosine.


 

exp

Answer the exponential of the receiver as a floating point number.


 

floorLog:

Answer the floor of the log base radix of the receiver.


 

interpolateTo:at:


 

ln

Answer the natural log of the receiver.


 

log

Answer the base-10 log of the receiver.


 

log:

Answer the log base aNumber of the receiver.


 

raisedTo:

Answer the receiver raised to aNumber.


 

raisedToInteger:

Answer the receiver raised to the power anInteger where the argument
must be a kind of Integer. This is a special case of raisedTo:.


 

sin

The receiver represents an angle measured in radians. Answer its sine.


 

sqrt

Answer the square root of the receiver.


 

squared

Answer the receiver multipled by itself.


 

tan

The receiver represents an angle measured in radians. Answer its
tangent.


  printing top  
 

defaultLabelForInspector

Answer the default label to be used for an Inspector window on the receiver.


 

isOrAreStringWith:


 

newTileMorphRepresentative


 

printOn:

Default print radix is 10


 

printStringBase:


 

storeOn:

Normal printing is OK for storing


 

storeOn:base:

Append my printed representation to aStream, incuding the base.


 

storeStringBase:


 

stringForReadout


  testing top  
 

basicType

Answer a symbol representing the inherent type of the receiver


 

even

Answer whether the receiver is an even number.


 

isDivisibleBy:


 

isInf


 

isInfinite


 

isNaN


 

isNumber

Overridden to return true in Number, natch


 

isZero


 

negative

Answer whether the receiver is mathematically negative.


 

odd

Answer whether the receiver is an odd number.


 

positive

Answer whether the receiver is positive or equal to 0. (ST-80 protocol).
See also strictlyPositive


 

sign

Answer 1 if the receiver is greater than 0, -1 if less than 0, else 0.


 

strictlyPositive

Answer whether the receiver is mathematically positive.


  truncation and round off top  
 

ceiling

Answer the integer nearest the receiver toward positive infinity.


 

detentBy:atMultiplesOf:snap:

Map all values that are within detent/2 of any multiple of grid to that multiple. Otherwise, if snap is true, return self, meaning that the values in the dead zone will never be returned. If snap is false, then expand the range between dead zones so that it covers the range between multiples of the grid, and scale the value by that factor.


 

floor

Answer the integer nearest the receiver toward negative infinity.


 

roundTo:

Answer the nearest number that is a multiple of quantum.


 

roundUpTo:

Answer the next multiple of aNumber toward infinity that is nearest the
receiver.


 

rounded

Answer the integer nearest the receiver.


 

truncateTo:

Answer the next multiple of aNumber toward zero that is nearest the
receiver.


 

truncated

Answer an integer nearest the receiver toward zero.


  vocabulary top  
 

vocabularyDemanded

Answer the vocabulary normally preferred by this object


class methods
  examples top  
 

exampleFor:

Provide a MethodCall with a valid example of aSelector, ready to run. If 'all', provide all tests we know about for SUnit tests. When 'all', each will be a Verifier, with an expected answer. Returns a list of MethodCalls, Verifiers, or VerifierOfPropertys.


  instance creation top  
 

readFrom:

Answer a number as described on aStream. The number may
include a leading radix specification, as in 16rFADE


 

readFrom:base:

Answer a number as described on aStream in the given number base.


 

readRemainderOf:from:base:withSign:

Read optional fractional part and exponent, and return the final result