Ada 中的双精度?

发布于 2024-08-29 18:30:18 字数 207 浏览 6 评论 0原文

我对 Ada 很陌生,想看看它是否提供双精度类型。我看到我们有浮点数,

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

在我的机器上给出的值为 6,这对于数值计算来说是不够的。

Ada 是否有像 C 中那样的 double 和 long double 类型?

多谢...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

下雨或天晴 2024-09-05 18:30:18

实际情况比这稍微复杂一点。

编译器必须支持的唯一预定义浮点类型是 Float。编译器可以选择支持 Short_FloatLong_Float。您应该能够查看编译器文档的附录 F 以了解它支持的内容。

实际上,您的编译器几乎肯定会将 Float 定义为 32 位 IEEE 浮点,将 Long_Float 定义为 64 位。请注意,C 语言的 floatdouble 也几乎以这种方式工作。 C 实际上并没有定义它们的大小。

如果您绝对必须具有一定的精度(例如:您正在与必须使用 IEEE 64 位的外部设备共享数据),那么您可能应该以完全相同的精度定义自己的浮点类型。这将确保您的代码可以移植到您将其移动到的任何平台或编译器,或者它会产生编译器错误,以便您可以解决问题。

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.

唔猫 2024-09-05 18:30:18

您可以创建任何您喜欢的大小的浮动。长期以来,它会是:

type My_Long_Float is digits 11;

Wiki Books 是此类内容的一个很好的参考。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文