Number
The number classes currently supported in CLDT are Integer, Fraction, and Float, which provide abstractions for the mathematical concepts of integers, rational numbers (fractions), and real numbers (floating point). The CLDT number classes do not deal explicitly with precision or other properties of numbers that depend on implementation. Another class, ScaledDecimal, deals explicitly with precision. The ScaledDecimal class is a subclass of Number and is defined in the DM subapp.
For example, a platform might support two or more implementations of a number class that have identical behavior, except that they represent numbers with different precisions or different signs. These classes would not be distinguished in CLDT. In contrast, most other Smalltalk systems support several different integer classes, such as SmallInteger, LargeInteger, LargePositiveInteger, and LargeNegativeInteger. Each class is constrained regarding the size or sign of the integers that it can represent. However, each of these classes supports the same Integer protocol defined in CLDT.
Developers do not usually need to be aware of the distinctions between the different representations of number classes, but at the same time the distinctions cannot be completely ignored. Some applications depend on knowledge of the platform-specific implementation of a number class and so are unlikely to be portable. An example is a numerical application in which the results depend on whether floating point numbers use single or double precision.
Porting tip:
Besides these implementation issues, Smalltalk/V includes a number of messages in the Number classes designed to support calculations for its particular graphics and windowing system. These are not supported in VA Smalltalk.
All number classes support the following basic protocol:
Arithmetic
*, +, -, /, //, \\, abs, negated, quo:, rem:
Converting
@, asFloat, asFraction, asInteger, degreesToRadians, radiansToDegrees
Porting tip:
Smalltalk/V does not support asFraction.
Testing
negative, positive, strictlyPositive
Enumerating
to:, to:by:, to:by:do:, to:do:
Generality
lessGeneralThan:, moreGeneralThan:
Note:
Some developers working with numerical operations applications occasionally need to determine the class of the return value when the receiver and the operand have different classes. The Blue Book specifies that the messages coerce:, generality, and retry: support explicit coercion (that is, type conversion, or casting) between numerical classes. These messages are used to perform the type checking required to ensure that the arguments of primitive methods have the correct type. For more details, see Chapter 8 of the Blue Book. In general, we believe that type checking and coercion should be regarded as a private implementation detail, and not exposed in application programming. lessGeneralThan: and moreGeneralThan: are designed to supply this information without revealing any details as to how the information is derived. In particular, there is no guarantee that number classes support an explicit integer-valued generality.
 
Porting tip:
Smalltalk/V and Objectworks\Smalltalk use different approaches than VA Smalltalk. Objectworks\Smalltalk follows and extends the Blue Book model, adding a large number of messages designed to support coercion and double dispatch. Smalltalk/V, on the other hand, hides most of the type checking inside primitive methods.
Math functions
arcCos, arcSin, arcTan, cos, exp, floorLog:, ln, log:, raisedTo:, raisedToInteger:, reciprocal, sign, sin, sqrt, squared, tan
Porting tip:
Smalltalk/V does not support floorLog:, and adds the message timesTwoPower:, which is not included in VA Smalltalk.
Truncating and rounding
ceiling, floor, rounded, roundTo:, truncated, truncateTo:
Last modified date: 04/20/2020