Ada Programming/Types/digits

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.

Description[edit | edit source]

To define a floating point type, you only have to say how many digits are needed, i.e. you define the relative precision:

digits Num_Digits

If you like, you can declare the minimum range needed as well:

digits Num_Digits range Low .. High

This facility is a great benefit of Ada over (most) other programming languages. In other languages, you just choose between "float" and "long float", and what most people do is:

  • choose float if they don't care about accuracy
  • otherwise, choose long float, because it is the best you can get

In either case, you don't know what accuracy you get.

In Ada, you specify the accuracy you need, and the compiler will choose an appropriate floating point type with at least the accuracy you asked for. This way, your requirement is guaranteed. Moreover, if the computer has more than two floating point types available, the compiler can make use of all of them.

See also[edit | edit source]

Wikibook[edit | edit source]

Ada Reference Manual[edit | edit source]