Ada 中的双精度?
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际情况比这稍微复杂一点。
编译器必须支持的唯一预定义浮点类型是 Float。编译器可以选择支持
Short_Float
和Long_Float
。您应该能够查看编译器文档的附录 F 以了解它支持的内容。实际上,您的编译器几乎肯定会将
Float
定义为 32 位 IEEE 浮点,将Long_Float
定义为 64 位。请注意,C 语言的float
和double
也几乎以这种方式工作。 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 supportShort_Float
andLong_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, andLong_Float
as a 64-bit. Note that C pretty much works this way too with itsfloat
anddouble
. 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.
您可以创建任何您喜欢的大小的浮动。长期以来,它会是:
Wiki Books 是此类内容的一个很好的参考。
You can create any size Float you like. For a long it would be:
Wiki Books is a good reference for things like this.