我正在阅读 Norman Cohen 的 Ada 95 书,在第 129 页上我们有常量声明:
Pi: constant Float := 3.1415926536
并且
Pi: constant := 3.1415926536
第二个声明据说被解释为,我引用:“具有适当范围的定点类型的任何浮点”。我的问题是说一个人正在使用 Long_Float 精度,那么例如要声明一个常量,比如 2*PI ,是否必须专门声明类似
Two_Pi : CONSTANT Long_Float := 2.0 * 3.1415926536
或更好:(
Two_Pi: CONSTANT Long_Float := 2.0 * Ada.Numerics.Pi;
第二个声明是为了利用小数点后的更多数字)?
是否会
Two_Pi : CONSTANT := 2.0 * 3.1415926536
或更好地
Two_Pi: CONSTANT := 2.0 * Ada.Numerics.Pi;
像书上声称的那样好,以便 Ada 编译器知道,例如,如果我在 Long_Float 计算中使用 Two_Pi,那么编译器将提供所需的精度位数?由于 Pi 值 3.1415926536 不是 Long_Float 类型(因为它的精度位数较少),因此我猜想
Two_Pi: CONSTANT := 2.0 * Ada.Numerics.Pi;
如果我在 Long_Float 计算中需要 Two_Pi ,则最后一个声明 ie 将是所需的全部内容。我理解对吗?具有类似的理解,then
Two_Pi: CONSTANT := 2.0 * Ada.Numerics.Pi;
也适用于 Float 类型计算,并且编译器将仅提供所需的精度位数。
多谢...
I'm reading Norman Cohen's Ada 95 book and on page 129 we have the constant declarations:
Pi: constant Float := 3.1415926536
and
Pi: constant := 3.1415926536
The second declaration is said to be interpreted as, I quote: "any floating-point of fixed-point type with the appropriate range". My question is say one is working with Long_Float precision, then for example to declare a constant say 2*PI do one has to specifically declare like
Two_Pi : CONSTANT Long_Float := 2.0 * 3.1415926536
or much better still:
Two_Pi: CONSTANT Long_Float := 2.0 * Ada.Numerics.Pi;
(the second declaration to take advantage of more digits after the decimal point) ?
Would
Two_Pi : CONSTANT := 2.0 * 3.1415926536
or better still
Two_Pi: CONSTANT := 2.0 * Ada.Numerics.Pi;
be as good as the book claims so that the Ada compiler would know for instance if I'm using Two_Pi in a Long_Float calculation, then the compiler would supply the required number of precision digits? Since the Pi value 3.1415926536 is not of Long_Float type (as it has fewer precision digits), I guess that the last declaration i.e.
Two_Pi: CONSTANT := 2.0 * Ada.Numerics.Pi;
would be all that is required if I need Two_Pi in a Long_Float calculation. Am I understanding right? With a similar understanding, then
Two_Pi: CONSTANT := 2.0 * Ada.Numerics.Pi;
would be relevant also in a Float type calculation and the compiler would supply only the required number of precision digits.
Thanks a lot...
发布评论
评论(1)
号码声明
例如有时称为命名号码。这样的数字是通用 “因为类中需要某些特定类型是可以接受的(参见 8.6)。"
附录:因为这些数字通用,它们可以“用作相应类中任何类型的原始子程序的操作数”。例如,
Two_Pi
可以乘以Float
、Long_Float
或从 universal_real 派生的任何类型。与此相关的是,您可能会喜欢 Ada 绑定到 GNU GMP 和 MPFR 库。
附录:绑定允许使用 Ada 中的 GNU 库,如 示例。
Number Declarations
such asare sometime called named numbers. Such a number is universal "in that it is acceptable where some particular type in the class is expected (see 8.6)."
Addendum: Because such numbers are universal, they can "be used as operands with the primitive subprograms of any type in the corresponding class." For example,
Two_Pi
can be multiplied byFloat
,Long_Float
or any type derived from universal_real.On a related note, you might like this Ada binding to the GNU GMP and MPFR libraries.
Addendum: The binding allows one to use the GNU libraries from Ada, as seen in this example.