Question

I'm very new to Ada and was trying to see if it offers double precision type. I see that we have float and

Put( Integer'Image( Float'digits ) );

on my machine gives a value of 6, which is not enough for numerical computations.

Does Ada has double and long double types as in C?

Thanks a lot...

Was it helpful?

Solution

It is a wee bit more complicated than that.

The only predefined floating-point type that compilers have to support is Float. Compilers may optionally support Short_Float and Long_Float. You should be able to look in appendex F of your compiler documentation to see what it supports.

In practice, your compiler almost certianly defines Float as a 32-bit IEEE float, and Long_Float as a 64-bit. Note that C pretty much works this way too with its float and double. C doesn't actually define the size of those.

If you absolutely must have a certian precision (eg: you are sharing the data with something external that must use IEEE 64-bit), then you should probably define your own float type with exactly that precision. That would ensure your code is either portable to any platform or compiler you move it to, or that it will produce a compiler error so you can fix the issue.

OTHER TIPS

You can create any size Float you like. For a long it would be:

type My_Long_Float is digits 11;

Wiki Books is a good reference for things like this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top