**Category: Language-Data types**

Superclass: Magnitude- I am an abstract class that provides operations on numbers, both floating point and integer. I provide some generic predicates, and supply the implicit type coercing code for binary operations.

testing (class)

arithmetic (instance)

coercion (instance)

comparing (instance)

converting (instance)

copying (instance)

error raising (instance)

misc math (instance)

point creation (instance)

retrying (instance)

shortcuts and iterators (instance)

testing (instance)

truncation and round off (instance)

Answer aNumber - whatever class it belongs to, it is good

**readFrom: aStream**

Answer the number read from the rest of aStream, converted to an instance of the receiver. If the receiver is number, the class of the result is undefined -- but the result is good.

**readFrom: aStream radix: anInteger**

Answer the number read from the rest of aStream, converted to an instance of the receiver. If the receiver is number, the class of the result is undefined -- but the result is good. The exponent (for example 1.2e-1) is only parsed if anInteger is 10.

Answer whether, if x is an instance of the receiver, x copy == x

Subtract the receiver and aNumber, answer the result

**+ aNumber**

Sum the receiver and aNumber, answer the result

**- aNumber**

Subtract aNumber from the receiver, answer the result

**/ aNumber**

Divide the receiver by aNumber, answer the result (no loss of precision). Raise a ZeroDivide exception or return a valid (possibly infinite) continuation value if aNumber is zero.

**// aNumber**

Return the integer quotient of dividing the receiver by aNumber with truncation towards negative infinity. Raise a ZeroDivide exception if aNumber is zero

**\\ aNumber**

Return the remainder of dividing the receiver by aNumber with truncation towards negative infinity. Raise a ZeroDivide exception if aNumber is zero

**quo: aNumber**

Return the integer quotient of dividing the receiver by aNumber with truncation towards zero. Raise a ZeroDivide exception if aNumber is zero

**reciprocal**

Return the reciprocal of the receiver

**rem: aNumber**

Return the remainder of dividing the receiver by aNumber with truncation towards zero. Raise a ZeroDivide exception if aNumber is zero

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

Answer the maximum between the receiver and aNumber. Redefine in subclasses if necessary to ensure that if either self or aNumber is a NaN, it is always answered.

**min: aNumber**

Answer the minimum between the receiver and aNumber. Redefine in subclasses if necessary to ensure that if either self or aNumber is a NaN, it is always answered.

Return the receiver, converted to a Fraction retaining the exact value of the receiver.

**asFloat**

Convert the receiver to an arbitrary subclass of Float

**asFloatD**

This method's functionality should be implemented by subclasses of Number

**asFloatE**

This method's functionality should be implemented by subclasses of Number

**asFloatQ**

This method's functionality should be implemented by subclasses of Number

**asFraction**

This method's functionality should be implemented by subclasses of Number

**asNumber**

Answer the receiver, since it is already a number

**asRectangle**

Answer an empty rectangle whose origin is (self asPoint)

**asScaledDecimal: n**

Answer the receiver, converted to a ScaledDecimal object.

**asScaledDecimal: denDigits radix: base scale: n**

Answer the receiver, divided by base^denDigits and converted to a ScaledDecimal object.

**asString**

Answer the receiver's #displayString, which should be a good enough conversion to String for a number.

**coerce: aNumber**

Answer aNumber, converted to an integer or floating-point number.

**degreesToRadians**

Convert the receiver to radians

**generality**

Answer the receiver's generality

**radiansToDegrees**

Convert the receiver from radians to degrees

**unity**

Coerce 1 to the receiver's class. The default implementation works, but is inefficient

**zero**

Coerce 0 to the receiver's class. The default implementation works, but is inefficient

Return the receiver - it's an immediate (immutable) object

**shallowCopy**

Return the receiver - it's an immediate (immutable) object

Raise an ArithmeticError exception having msg as its message text.

**zeroDivide**

Raise a division-by-zero (ZeroDivide) exception whose dividend is the receiver.

Answer the absolute value of the receiver

**arcCos**

Answer the arc cosine of the receiver

**arcCosh**

Answer the hyperbolic arc-cosine of the receiver.

**arcSin**

Answer the arc sine of the receiver

**arcSinh**

Answer the hyperbolic arc-sine of the receiver.

**arcTan**

Answer the arc tangent of the receiver

**arcTan: x**

Answer the angle (measured counterclockwise) between (x, self) and a ray starting in (0, 0) and moving towards (1, 0) - i.e. 3 o'clock

**arcTanh**

Answer the hyperbolic arc-tangent of the receiver.

**ceilingLog: radix**

Answer (self log: radix) ceiling. Optimized to answer an integer.

**cos**

Answer the cosine of the receiver

**cosh**

Answer the hyperbolic cosine of the receiver.

**estimatedLog**

Answer an estimate of (self abs floorLog: 10). This method should be overridden by subclasses, but Number's implementation does not raise errors - simply, it gives a correct result, so it is slow.

**exp**

Answer e raised to the receiver

**floorLog: radix**

Answer (self log: radix) floor. Optimized to answer an integer.

**ln**

Answer log base e of the receiver

**log**

Answer log base 10 of the receiver

**log: aNumber**

Answer log base aNumber of the receiver

**negated**

Answer the negated of the receiver

**positiveDifference: aNumber**

Answer the positive difference of the receiver and aNumber, that is self - aNumber if it is positive, 0 otherwise.

**raisedTo: aNumber**

Return self raised to aNumber power

**raisedToInteger: anInteger**

Return self raised to the anInteger-th power

**sin**

Answer the sine of the receiver

**sinh**

Answer the hyperbolic sine of the receiver.

**sqrt**

Answer the square root of the receiver

**squared**

Answer the square of the receiver

**tan**

Answer the tangent of the receiver

**tanh**

Answer the hyperbolic tangent of the receiver.

**withSignOf: aNumber**

Answer the receiver, with its sign possibly changed to match that of aNumber.

Answer a new point whose x is the receiver and whose y is y

**asPoint**

Answer a new point, self @ self

Coerce to the other number's class the one number between the receiver and aNumber which has the lowest, and retry calling aSymbol. aSymbol is supposed not to be #= or #~= (since those don't fail if aNumber is not a Number).

**retryDifferenceCoercing: aNumber**

Coerce to the other number's class the one number between the receiver and aNumber which has the lowest, and retry calling #-.

**retryDivisionCoercing: aNumber**

Coerce to the other number's class the one number between the receiver and aNumber which has the lowest, and retry calling #/.

**retryEqualityCoercing: aNumber**

Coerce to the other number's class the one number between the receiver and aNumber which has the lowest, and retry calling #=.

**retryError**

Raise an error---a retrying method was called with two arguments having the same generality.

**retryInequalityCoercing: aNumber**

Coerce to the other number's class the one number between the receiver and aNumber which has the lowest, and retry calling #~=.

**retryMultiplicationCoercing: aNumber**

Coerce to the other number's class the one number between the receiver and aNumber which has the lowest, and retry calling #*.

**retryRelationalOp: aSymbol coercing: aNumber**

Coerce to the other number's class the one number between the receiver and aNumber which has the lowest, and retry calling aSymbol (<, <=, >, >=).

**retrySumCoercing: aNumber**

Coerce to the other number's class the one number between the receiver and aNumber which has the lowest, and retry calling #+.

Return an interval going from the receiver to stop by 1

**to: stop by: step**

Return an interval going from the receiver to stop with the given step

**to: stop by: step collect: aBlock**

Evaluate aBlock for each value in the interval going from the receiver to stop with the given step. The results are collected in an Array and returned.

**to: stop by: step do: aBlock**

Evaluate aBlock for each value in the interval going from the receiver to stop with the given step. Compiled in-line for integer literal steps, and for one-argument aBlocks without temporaries, and therefore not overridable.

**to: stop collect: aBlock**

Evaluate aBlock for each value in the interval going from the receiver to stop by 1. The results are collected in an Array and returned.

**to: stop do: aBlock**

Evaluate aBlock for each value in the interval going from the receiver to stop by 1. Compiled in-line for one-argument aBlocks without temporaries, and therefore not overridable.

Answer whether the receiver can be considered sufficiently close to num (this is done by checking equality if num is not a number, and by checking with 0.01% tolerance if num is a number).

**even**

Returns true if self is divisible by 2

**isExact**

Answer whether the receiver performs exact arithmetic. Most numeric classes do (in fact the only exceptions is Float and its descendants), so the default is to answer true rather than calling #subclassResponsibility.

**isFinite**

Answer whether the receiver represents a finite quantity. Most numeric classes are for finite quantities, so the default is to answer true rather than calling #subclassResponsibility.

**isInfinite**

Answer whether the receiver represents an infinite quantity. Most numeric classes are for finite quantities, so the default is to answer false rather than calling #subclassResponsibility.

**isNaN**

Answer whether the receiver is a Not-A-Number. Most numeric classes don't handle nans, so the default is to answer false rather than calling #subclassResponsibility.

**isNumber**

Answer `true'.

**isRational**

Answer whether the receiver is rational - false by default

**negative**

Answer whether the receiver is < 0

**odd**

Returns true if self is not divisible by 2

**positive**

Answer whether the receiver is >= 0

**sign**

Returns the sign of the receiver.

**strictlyPositive**

Answer whether the receiver is > 0

Answer the receiver, rounded to the nearest integer

**floor**

Return the integer nearest the receiver toward negative infinity.

**fractionPart**

Answer a number which, summed to the #integerPart of the receiver, gives the receiver itself.

**integerPart**

Answer the receiver, truncated towards zero

**roundTo: aNumber**

Answer the receiver, truncated to the nearest multiple of aNumber

**rounded**

Returns the integer nearest the receiver

**truncateTo: aNumber**

Answer the receiver, truncated towards zero to a multiple of aNumber

**truncated**

Answer the receiver, truncated towards zero