18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>Ada</strong> <strong>in</strong>troduction: Part 2 53<br />

Note 3<br />

Note 4<br />

A fixed po<strong>in</strong>t number is effectively composed of two components: the<br />

whole part and the fractional part stored <strong>in</strong> an <strong>in</strong>teger value. This can<br />

lead to more efficient arithmetic on a mach<strong>in</strong>e which does not have<br />

float<strong>in</strong>g po<strong>in</strong>t hardware or where the implementation of float<strong>in</strong>g po<strong>in</strong>t<br />

arithmetic is slow. It also provides a precise way of deal<strong>in</strong>g with numbers<br />

that have a decimal po<strong>in</strong>t.<br />

An alternative notation for a decimal fixed po<strong>in</strong>t type is:<br />

type Miles is delta 0.1 digits 8 range 0.0 .. 10.0;<br />

However, even though all compilers must parse this type declaration they<br />

only need to support it if the compiler implements the Information systems<br />

Annex.<br />

A float<strong>in</strong>g po<strong>in</strong>t number.<br />

An alternative type declaration is:<br />

type Miles is digits 8;<br />

which def<strong>in</strong>es the precision 8 digits but not the range of values that may<br />

be stored.<br />

4.14.1 The <strong>in</strong>built types<br />

<strong>Ada</strong> provides the follow<strong>in</strong>g <strong>in</strong>built types.<br />

Type Classification An <strong>in</strong>stance of the type<br />

Boolean Enumeration Holds either True or False.<br />

Character Enumeration Holds a character based on the ISO 8859-1<br />

character set. In which there are 256 dist<strong>in</strong>ct<br />

characters.<br />

Float Float Holds numbers which conta<strong>in</strong> a decimal<br />

place.<br />

Integer Integer Holds whole numbers.<br />

Wide_character Enumeration Holds a character based on the ISO 10646<br />

BMP character set. In which there are 65536<br />

dist<strong>in</strong>ct characters.<br />

The implementation m<strong>in</strong>imum values for these types are given <strong>in</strong> Section B.6, Appendix B.<br />

4.15 Arithmetic operators<br />

The arithmetic operators <strong>in</strong> <strong>Ada</strong> <strong>95</strong> are:<br />

+ Addition<br />

- Subtraction<br />

* Multiplication<br />

/ Division<br />

The follow<strong>in</strong>g arithmetic operators are def<strong>in</strong>ed on <strong>in</strong>teger values only:<br />

mod<br />

rem<br />

abs<br />

Modulus<br />

Rema<strong>in</strong>der<br />

Returns the absolute value<br />

The operators mod and rem are similar, and will give identical results when both operands have the same sign.<br />

The operator rem gives a rema<strong>in</strong>der correspond<strong>in</strong>g to the <strong>in</strong>teger division operation /. The consequence of this is<br />

that as <strong>in</strong>teger division truncates towards 0, the absolute value of the result will always be the same regardless of<br />

© M A Smith - May not be reproduced without permission

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

Saved successfully!

Ooh no, something went wrong!