this documentation is work-in-progress, edit here (md).

Numbers

sections in this chapter:
[ Number ] > [ Number ] »
[ Number ] >=: [ Number ] »
[ Number ] < [ Number ] »
[ Number ] <=: [ Number ] »
[ Number ] = [ Number ] »
[ Number ] !=: [ Number ] »
[ Number ] between: [ Number ] and: [ Number ] »
[ Number ] odd? »
[ Number ] even? »
[ Number ] + [ Number ] »
[ Number ] add: [ Number ] »
[ Number ] - [ Number ] »
[ Number ] subtract: [ Number ] »
[ Number ] * [ Number ] »
[ Number ] multiply by: [ Number ] »
[ Number ] / [ Number ] »
[ Number ] divide by: [ Number ] »
[ Number ] modulo: [ modulo ] »
[ Number ] power: [ Number ] »
[ Number ] positive? »
[ Number ] negative? »
[ Number ] floor »
[ Number ] [ String ] »
[ Number ] qualifier. »
[ Number ] ceil »
[ Number ] round »
[ Number ] absolute »
[ Number ] square root »
[ Number ] sin »
[ Number ] cos »
[ Number ] tan »
[ Number ] atan »
[ Number ] log »
[ Number ] & [ Number ] »
[ Number ] | [ Number ] »
[ Number ] ^ [ Number ] »
[ Number ] string »
[ Number ] raw »
[ Number ] boolean »
[ Int64 ] from-string: [ String ] »

Each time you write a number, for example 9, -10, or 3,12, behind the screen, Xoscript will convert these numbers into a Number object. You can send messages to this Number object, or you could assign the number to a variable and send messages afterwards:

10 even?

>> tenner := 10.
tenner even?

Both notations are valid. The Number object responds to the following messages…

Most of these messages are self-explanatory and allow you to execute mathematical operations or comparisons.

Note
Note that you may use ≤ ≥ ≠ × and ÷ instead their ASCII counterparts. This is a matter of preference.

The difference between binary mathematical messages (+) and their keyword variations (add:) is that the former will return a new number, which is the result of the operation, whereas with the latter the object itself will be modified. This is illustrated in the following example:

Example:

>> a := 1.
>> b := a + 3.
a add: 2.

Out write: a, stop.
Out write: b, stop.

	

Result:

3
4

	

In the above example, b = 4 and a = 3. With add: 2 the value of a is raised by 2, while + 3 creates a new number that is equal to a + 3. The same applies to other mathematical processes, e.g., multiplications. By using the multiplication symbol, you will receive a new object as answer. In case you use the message multiply-by:, you will multiply the number itself.

With the message between:and:, for example in: Number between: X and: Y, you will get a number between X and Y. In this way, any random number can be generated:

>> a := Number between: 1 and: 10.
Out write: a, stop.

As of version 1.4, the build-in generator of random numbers in xoscript is crypogrpahically secure to the best of our knowledge.

You can attach a qualifier to a number, for instance, 6 apples. Each message that does not get recognised by a number will be considered a qualifier. You can retrieve the qualifier of a number by means of the message qualifier:

A qualifier is basically a Text object that is stored with the Number object. The qualifier is also printed after the number on a write: assignment. Qualifiers could be used to add amounts in mixed currencies for example. On adding the amounts, you can ask for the qualifiers. The following program example illustrates this principle by using a historical currency calculator (as the exchange rate remains reasonably stable!).

Example:


Number learn: ['plus:'] means: ['+'].
Number on: ['+'] do: { :x
	>> rate := 1.
	>> currency := x qualifier.
	(currency = ['euros']) true: {
		rate := 2.
	}. <- (self plus: (x × rate)).
}.
>> dollars := 3.
>> euros := 2.
dollars qualify: ['dollars'].
euros qualify: ['euros'].
>> money := dollars + euros.
Out write: money, stop.

	

Result:

7

	

[ Number ] > [ Number ]

Example:


 Out write: 8 > 7, stop.
 Out write: 7 > 8, stop.
 
	

Result:

True
False

	

[ Number ] >=: [ Number ]

Example:


 >> x := ( 8 >=: 7 ).
 Out write: x, stop.
 
	

Result:

True

	

[ Number ] < [ Number ]

Example:


 >> x := 8 < 7.
 >> y := 7 < 8.
 Out write: x, stop.
 Out write: y, stop. 
 
	

Result:

False
True

	

[ Number ] <=: [ Number ]

Example:


 >> x := ( 8 <=: 7 ).
 >> y := 7 ≤ 8.
 Out write: x, stop.
 Out write: y, stop. 
 
	

Result:

False
True

	

[ Number ] = [ Number ]

Example:


 >> x := 8 = 8.
 >> y := 8 = 9.
 Out write: x, stop.
 Out write: y, stop.
 
	

Result:

True
False

	

[ Number ] !=: [ Number ]

Example:


 >> x := ( 8 !=: 8 ).
 >> y := 8 ≠ 9.
 Out write: x, stop.
 Out write: y, stop.
 
	

Result:

False
True

	

[ Number ] between: [ Number ] and: [ Number ]

Example:


 >> x := Number between: 0 and: 10.
 Out write: ((x >=: 0) and: (x <=: 10)), stop.
 

	

Result:

True

	

[ Number ] odd?

Example:


 Out write: 2 odd?, stop.
 Out write: 3 odd?, stop.
 
	

Result:

False
True

	

[ Number ] even?

Example:


 Out write: 2 even?, stop.
 Out write: 3 even?, stop.
 
	

Result:

True
False

	

[ Number ] + [ Number ]

Example:


 >> x := 2 + 2.
 >> y := x + 0.5.
 Out write: x, stop.
 Out write: y, stop.
 
	

Result:

4
4.5

	

[ Number ] add: [ Number ]

Example:


 >> x := 1.
 x add: 2.
 Out write: x, stop.
 
	

Result:

3

	

[ Number ] - [ Number ]

Example:


 >> x := 9.
 >> y := x - 4.
 Out write: y, stop.
 
	

Result:

5

	

[ Number ] subtract: [ Number ]

Example:


 >> x := 3.
 x subtract: 1.
 Out write: x, stop.
 
	

Result:

2

	

[ Number ] * [ Number ]

Example:


 >> x := 3 * 3.
 Out write: x, stop.
 
	

Result:

9

	

[ Number ] multiply by: [ Number ]

Example:


 >> x := 5.
 x multiply-by: 2.
 Out write: x, stop.
 
	

Result:

10

	

[ Number ] / [ Number ]

Example:


 Out write: 10 / 2, stop.
 
	

Result:

5

	

[ Number ] divide by: [ Number ]

Example:


 >> x := 10.
 x divide-by: 2.
 Out write: x, stop.
 
	

Result:

5

	

[ Number ] modulo: [ modulo ]

Example:


 >> x := 11 modulo: 3.
 Out write: x, stop.
 
	

Result:

2

	

[ Number ] power: [ Number ]

Example:


 Out write: (2 power: 3).
 
	

Result:

8
	

[ Number ] positive?

Example:


 { :i 
 Out write: ( i - 5 ) positive?, stop.
 } × 10.
 
	

Result:

False
False
False
False
False
False
True
True
True
True

	

[ Number ] negative?

Example:


 { :i 
 Out write: ( i - 5 ) negative?, stop.
 } × 10.
 
	

Result:

True
True
True
True
True
False
False
False
False
False

	

[ Number ] floor

Example:


 >> x := 4.5.
 Out write: x floor, stop.
 
	

Result:

4

	

[ Number ] [ String ]

Example:


 >> x := 3 dollars.
 Out write: x qualifier.
 
 
	

Result:

dollars
	

[ Number ] qualifier.

Example:


 >> x := 3 dollars.
 Out write: x qualifier.
 
	

Result:

dollars
	

[ Number ] ceil

Example:


 >> x := 4.5.
 Out write: x ceil, stop.
 
	

Result:

5

	

[ Number ] round

Example:


 >> x := 5.5.
 Out write: x round, stop.
 
	

Result:

6

	

[ Number ] absolute

Example:


 >> x := -7.
 Out write: x absolute, stop.
 
	

Result:

-7 absolute

	

[ Number ] square root

Example:


 >> x := 49.
 >> y := x sqrt.
 Out write: y, stop.
 

	

Result:

7

	

[ Number ] sin

Example:


 Out write: 123 sin, stop.
 
	

Result:

-0.4599034907

	

[ Number ] cos

Example:


 Out write: 123 cos, stop.
 
	

Result:

-0.8879689067

	

[ Number ] tan

Example:


 Out write: 123 tan, stop.
 
	

Result:

0.5179274716

	

[ Number ] atan

Example:


 Out write: 123 atan, stop.
 
	

Result:

1.5626664246

	

[ Number ] log

Example:


 Out write: 123 log, stop.
 
	

Result:

4.8121843554

	

[ Number ] & [ Number ]

Example:


 Out write: (8 & 10), stop.
 
	

Result:

8

	

[ Number ] | [ Number ]

Example:


 Out write: (8 | 10), stop.
 
	

Result:

10

	

[ Number ] ^ [ Number ]

Example:


 Out write: (8 ^ 10), stop.
 
	

Result:

2

	

[ Number ] string

Example:


 >> x := 123.
 Out write: x, stop.
 >> x := 1.23.
 Out write: x, stop.
 >> x := 1,000,000.
 Out write: x, stop.
 
	

Result:

Parse error, unexpected , ( ../../../tests/t-0456.ctr: 6 )
Expected a dot (.).

	

[ Number ] raw

Example:


 >> x := 123.
 Out write: x plain, stop.
 >> x := 1.23.
 Out write: x plain, stop.
 >> x := 1,000,000.
 Out write: x plain, stop.
 
	

Result:

Parse error, unexpected , ( ../../../tests/t-0457.ctr: 6 )
Expected a dot (.).

	

[ Number ] boolean

Example:


 { :i
 	Out write: (i - 1) bool, stop.
 } × 10.
 
	

Result:

True
False
True
True
True
True
True
True
True
True

	

[ Int64 ] from-string: [ String ]

Example:



# create a 64-bit integer for exact calculations
>> a := Int64 from-string: ['123'].

# to string
Out write: a, stop.

# divide
Out write: a / (Int64 from-string: ['3']), stop.

# multiply
Out write: a * (Int64 from-string: ['2']), stop.

# add
Out write: a + (Int64 from-string: ['1']), stop.

# subtract
Out write: a - (Int64 from-string: ['2']), stop.

# compare
Out write: ( a =   (Int64 from-string: ['123'])), stop.
Out write: ( a !=: (Int64 from-string: ['124'])), stop.
Out write: ( a <   (Int64 from-string: ['124'])), stop.
Out write: ( a >   (Int64 from-string: ['122'])), stop.
Out write: ( a >=: (Int64 from-string: ['123'])), stop.
Out write: ( a <=: (Int64 from-string: ['123'])), stop.





	
	

Result:

123
41
246
124
121
True
True
True
True
True
True