Math

Last updated at 4:31 pm UTC on 11 November 2006

Squeak is very well capable of doing advanced math, dynamic typing is essential for making easy coercions between different nummeric type, the biggest flaw is in speed where it cannot compete with machine-code-compiled languages as pascal, c, c++ and fortran - but for far the most purposes squeak on a modern machine will do the trick.When you're doing math in squeak, then remember that the precedence rules you know from your math-lessons isn't obeyed by squeak (binary messages are send from left to right): 3+2 * 5 returns 25, NOT 15 - so put in parantheses whenever in doubt.

This is a quick review of what is possible, browse the classes for further methods and information, theres plenty.

- SmallInteger - machine-integers (31 bits, that is in the range -2^30 - 2^30-1) examples:

- LargePositiveInteger LargeNegativeInteger - this is numbers numerically too large for SmallInteger (only limited by memory) examples are:

- Float - IEEE-754 floating-point double-precision numbers. They have about 16 digits of accuracy and their range is between plus and minus 10^307. Some valid examples are:

- Fraction - dealing with proportions between integers, makes possible to have excact representations of eg. 1/3.
- Complex number support has been added with 3.8, a complex number is created from a non-complex by the method 'i', or with the constructors real:imaginary: and/or abs:arg: examples:

You can also do some arithmetic on points (as 2d- and 3d-vectors), they are created like this -2@5. 4.23e6@44.

(also see literals)

< >= = =

- + - * / abs negated reciprocal squared

- sin cos tan - Std. geometric functions works in radians.
- degreeSin degreeCos degreeTan - The same in degrees.
- sinh cosh - hyperbole versions for Complex numbers.
- arcSin arcCos arcTan - the inverse trig funtions

- raisedTo: - the receiver raised to the argument
- raisedToInteger: - a lot faster.
- sqrt returns the squareroot of the receiver
- exp - e raised to the receiver power
- ln - base e logarithm
- log - base 10 logarithm
- log: - logarithm to any base

- 5 atRandom - returns a Integer between 1 (inclusive) and 5 inclusive
- #(1 4 2) atRandom - returns a random element from the Array (or any other Collection)
- #(1 2 3) shuffle - permutates the OrderedCollection

- Cassowary - An incremental constraint solving toolkit that efficiently solves systems of linear equalities and inequalities..
- Graph, Graphs, KGraph - Graph packages
- Logic Expressions Expressions - A model of first order logic expressions.