Tutorial by Examples

type Fruit is (Banana, Orange, Pear); Choice : Fruit := Banana; A character type is an enumeration that includes a character literal: type Roman_Numeral is ('I', 'V', 'X', 'L', 'C', 'D', 'M', Unknown);`
type Grade is range 0 .. 15; B : Grade := 11; C : Grade := 8; Avg : Grade := (B + C) / 2; -- Avg = 9
These are the “bit fiddling” types. They have logical operators, too, such as xor, and they “wrap around” at the upper bound, to 0 again. type Bits is mod 2**24; L : Bits := 2#00001000_01010000_11001100# or 7;
A floating point type is characterised by its (decimal) digits which state the minimal precision requested. type Distance is digits 8; Earth : Distance := 40_075.017;
A fixed point type definition specifies a delta, and a range. Together, they describe how precisely real values should be approximated as they are represented by powers of two, not using floating point hardware. Shoe_Ounce : constant := 2.54 / 64.0; type Thickness is delta Shoe_Ounce range 0.00 .....
Decimal fixed point types are typically used in accounting. They are characterised by both a delta and a number of decimal digits. Their arithmetical operations reflect the rules of accounting. type Money is delta 0.001 digits 10; Oil_Price : Money := 56.402; Loss : Money := 0.002 / 3; -- ...

Page 1 of 1