Thus, an operation that involves a float and scaled decimal usually produces a floating-point result, and an operation involving a fraction and an integer usually produces a fraction as a result. Messages are also provided for the explicit conversion of numbers to the various numeric types:
Protocol <number>
| Conforms to: <magnitude>
|
Messages:
|
* <number> ^ <number>
| Multiplication
|
+ <number> ^ <number>
| Addition
|
- <number> ^ <number>
| Subtraction
|
/ <number> ^ <number>
| Division
|
// <number> ^ <integer>
| Division truncated towards negative infinity
|
\\ <number> ^ <number>
| Remainder of // division
|
abs ^ <number>
| Absolute value
|
asFloat ^ <float>
| Convert to floating point number
|
asFraction ^ <fraction>
| Convert to fraction number
|
asInteger ^ <integer>
| Convert to integer number (rounded)
|
asScaledDecimal ^ <scaledDecimal>
| Convert to scaled decimal number
|
ceiling ^ <integer>
| Smallest integer >= receiver
|
floor ^ <integer>
| Largest integer <= receiver
|
negated ^ <number>
| Negation
|
negative ^ <boolean>
| Test is receiver is less than 0
|
positive ^ <boolean>
| Test is receiver is greater than or equal to 0
|
quo: <number> ^ <integer>
| Division truncated towards zero
|
raisedToInteger: <integer> ^ <number>
| Receiver raised to the argument power
|
reciprocal ^ <number>
| 1 divided by the receiver
|
rem: <number> ^ <number>
| Remainder of rem: division
|
rounded ^ <integer>
| Round receiver to nearest integer
|
roundedTo: <number> ^ <number>
| Round to nearest multiple of argument
|
sign ^ <integer>
| Encode receivers sign as an integer (-1,0,+1)
|
sqrt ^ <float>
| Positive square root
|
squared ^ <number>
| Square of the receiver
|
strictlyPositive ^ <boolean>
| Tests whether receiver is greater than zero
|
to: <number> ^ <Interval>
| Creates an interval whose step is one
|
to: <number> by: <number> ^ <Interval>
| Creates an interval
|
to: <number> by: <number> do: <block1> ^ <Object>
| Evaluates block for each member of an interval
|
to: <number> do: <block1> ^ <Object>
| Evaluates block for each member of an interval
|
truncated ^ <integer>
| Truncates to nearest integer towards zero
|
truncateTo: <number> ^ <number>
| Truncates to a multiple of the argument
|
Integers have arbitrary precision. The number of digits in an integer object is limited only by the available memory of the computer. It is common for a Smalltalk implementation to use several different classes and encodings for integer objects, depending on the size and sign of the integer value. Regardless of their class, bit manipulation operations are valid only for positive integers and operate as if their values were encoded using binary notation. All integer classes conform to the protocol <integer>:
Protocol <integer>
| Conforms to: <number>
|
Messages:
|
allMask: <integer> ^ <boolean>
| Tests if all masked bits are set
|
anyMask: <integer> ^ <boolean>
| Tests if any masked bit is set
|
bitAnd: <integer> ^ <integer>
| Bitwise logical and
|
bitAt: <integer> ^ <integer>
| Value of bit at the indexed position
|
bitOr: <integer> ^ <integer>
| Bitwise logical or
|
bitShift: <integer> ^ <integer>
| Shifts the bits right or left
|
bitXor: <integer> ^ <integer>
| Bitwise logical exclusive or
|
clearBit: <integer> ^ <integer>
| Clears the bit at the indexed position
|
even ^ <boolean>
| Tests if evenly divisible by 2
|
factorial <integer>
| Computes factorial of the receiver
|
gcd: <integer> ^ <integer>
| Computes greatest common divisor
|
highBit ^ <integer>
| Index position of most significant non-zero bit
|
isBitSet: <integer> ^ <boolean>
| Tests state of bit at the indexed position
|
lcm: <integer> ^ <integer>
| Computes least common multiple
|
noMask: <integer> ^ <boolean>
| Tests if no masked bits are set
|
odd ^ <boolean>
| Tests if not evenly divisible by 2
|
printOn: <writeStream> base: <integer>
| Writes text of number to a stream in a specified base
|
printStringRadix: <integer>
| Returns the text of number in specified base
|