Ada 95 Quality and Style Guide Chapter 3

### Chapter 3: Readability - TOC - 3.1 SPELLING

3.1.2 Numbers

guideline

• Represent numbers in a consistent fashion.
• Represent literals in a radix appropriate to the problem.
• Use underscores to separate digits the same way commas or periods (or spaces for nondecimal bases) would be used in normal text.
• When using scientific notation, make the E consistently either uppercase or lowercase.
• In an alternate base, represent the alphabetic characters in either all uppercase or all lowercase.

• instantiation

- Decimal and octal numbers are grouped by threes beginning on the left side of the radix point and by fives beginning on the right side of the radix point.
- The E is always capitalized in scientific notation.
- Use uppercase for the alphabetic characters representing digits in bases above 10.
- Hexadecimal numbers are grouped by fours beginning on either side of the radix point.

example

```type Maximum_Samples     is range          1 ..  1_000_000;
type Legal_Hex_Address   is range   16#0000# ..   16#FFFF#;
type Legal_Octal_Address is range 8#000_000# .. 8#777_777#;
```

To represent the number 1/3 as a constant, use:

```One_Third : constant := 1.0 / 3.0;
```

Avoid this use:

```One_Third_As_Decimal_Approximation : constant := 0.33333_33333_3333;
```

or:

```One_Third_Base_3 : constant := 3#0.1#;
```

rationale

Consistent use of uppercase or lowercase aids scanning for numbers. Underscores serve to group portions of numbers into familiar patterns. Consistency with common use in everyday contexts is a large part of readability.

notes

If a rational fraction is represented in a base in which it has a terminating rather than a repeating representation, as 3#0.1# does in the example above, it may have increased accuracy upon conversion to the machine base.

 < Previous Page Search Contents Index Next Page >
 1 2 3 4 5 6 7 8 9 10 11 TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC
 Appendix References Bibliography