06.06.2013 Views

Computer Programming with GNU Smalltalk - Free

Computer Programming with GNU Smalltalk - Free

Computer Programming with GNU Smalltalk - Free

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

30 <strong>Computer</strong> <strong>Programming</strong> <strong>with</strong> <strong>GNU</strong> <strong>Smalltalk</strong><br />

0.0<br />

3.1 integerPart<br />

3.0<br />

truncated<br />

To truncate a decimal number we use truncated message:<br />

17.2 truncated<br />

17<br />

Note that this is not rounding:<br />

17.6 truncated<br />

17<br />

To round decimal numbers we use...<br />

rounded<br />

rounded message:<br />

17.6 rounded<br />

18<br />

Let us see some messages special to fractional numbers.<br />

denominator<br />

To get the denominator of a fractional number we use denominator message:<br />

3<br />

(3/4) denominator<br />

Notice that we parenthesized the expression 3/4. The reason is that if we didn't do that then the unary<br />

message denominator would be calculated before the expression 3/4 because, as we said before,<br />

unary messages are evaluated before binary messages.<br />

numerator<br />

We use numerator message to get the numerator of a fractional number:<br />

4<br />

(3/4) numerator

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!