A Glance at Numbers

Damien Cassou, Stéphane Ducasse and Luc Fabresse http://stephane.ducasse.free.fr

Numbers

Numbers

.

Small Integers are Real Objects

	1 class
	> SmallInteger

Small integers are optimized

But small integers are heavily optimized

    2 raisedTo: 30  
    > 1073741823
    SmallInteger maxVal
    > 1073741823

Automatic Coercion

What is the largest small integer?

	1 class maxVal
	> 1073741823

What is the smallest large integer?

	1 class maxVal +1
	> 1073741824

	(1 class maxVal + 1) class
	> LargePositiveInteger

Fun With Numbers

Fun With Large Numbers

factorial is not optimized

1000 factorial numberOfDigits
> 2568 
100000 factorial numberOfDigits
> 456574 

Fraction

Fraction

1000 factorial / 999 factorial
> 1000

Messages Sent to Objects

	(1 / 3) + (2 / 3)
	>1
	2 / 3 + 1
	> 5 / 3

Message Limits

2 * 3 + 5
> 11
2 + 3 * 5 
> 25 !!!
2 + (3 * 5)
> 11

Points

10 @ 100
(10 @ 100) x
> 10
(10 @ 100) y
>100

Alternative

Point new x: 100 y: 100

Class written in a functional way: Most Point methods are returning new points

Rectangles

Rectangle left: 10 right: 100 top: 20  bottom: 40
> (10@20) corner: (100@40)
Rectangle origin: 20@20	corner: 100@200

Margins

  • Delta to apply to a rectangle
  • Useful for GUI
  • Encodes 4 numbers, expressed in 3 different ways
    • a number (same space all around)
    • two numbers (same left/right and top/bottom)
    • four numbers
  • Used to compute the extended (or inner) rectangle

.

Summary

/