views:

173

answers:

2

Hi, 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...

+4  A: 

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.

T.E.D.
Thanks. I tried Long_Float and I got 15 digits :) and I'm very happy with this :). I'm using the AdaGIDE IDE with GNAT compiler.
yCalleecharan
Gnat on x86's actually supports a (totally non-portable) Long_Long_Float that uses all 80 digits the Intel FPU's have, if you want to go hog-wild.
T.E.D.
I get 18 digits with Long_Long_Float. This is largely more than enough for numerical calculations.
yCalleecharan
Errr...I meant 80 **bits**, not 80 digits of course. Doh.
T.E.D.
+4  A: 

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.

mamboking
I'm very new to Ada. I'm testing my IDE and compiler and see if I can run Ada programs. Thanks for your answer.
yCalleecharan
This is true. In practice, you might have a bit of trouble using oddball floats that aren't compatible with your FPU (assuming you want hardware floats). However, this is exactly what you want to do if you have an exact size float you want to use, no matter what compiler/platform your code ends up on.
T.E.D.