Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
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.

Different nummeric classes

Squeak comes with support for:
5 -42 2r100101 16rFA -36RZ
SmallInteger maxVal + 1. 1000 factorial negated.
8.0. 13.3. 0.3. 2.5e6. 1.27e-30. 1.27e-31. -12.987654e12. (Float pi) (Float infinity)
3 + 5 i. Complex abs: 5 arg: (Float pi / 4)

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)

Mathematical functions

All instances of number supports the following messages:

Comparison

Apart from complex numbers (which can only be compared for equality), all numbers can be compared with:
< >= = =

Arithmetic:

Integers also support gcd: factorial and lcd:

Trig:


Powers and Logarithms


Random numbers

The random-number-generator is a Park-Miller generator, it is implemented in the class Random.


More advanced functionality

Squeak has - compared to many other languages a very rich array of mathematical functions, also some that are so non-trivial in their implementation that it could be asked if they're too specific - but it's a joy for doing homework-sort of math. There's some more advanced packages for math you can download from SqueakMap, including: