使用Ada(GNAT):我需要确定给定值的十次幂。最明显的方法是使用对数;但是没有编译。您如何编码以确定Ada中某个值的对数?
with Ada.Numerics.Generic_Elementary_Functions;
procedure F(Value : in Float) is
The_Log : Integer := 0;
begin
The_Log := Integer(Log(Value, 10));
G(Value, The_Log);
end;
错误:
- utilities.adb:495:26: “日志” 是不可见的
- utilities.adb:495:26: 不可见的A-声明ngelfu.ads:24,实例在线482
- utilities.adb:495:26: 不可见声明在a-ngelfu.ads:23,实例在线482
于是我试图指包,但也失败:
with Ada.Numerics.Generic_Elementary_Functions;
procedure F(Value : in Float) is
The_Log : Integer := 0;
package Float_Functions is new Ada.Numerics.Generic_Elementary_Functions (Float);
begin
The_Log := Integer(Float_Functions.Log(Value, 10));
G(Value, The_Log);
end;
错误:
- utilities.adb:495:41:没有候选人解释符合实际情况:
- utilities.adb:495:41:调用“Log”的参数太多
- utilities.adb:495:53:预计类型“Standard.Float”
- utilities.adb:495:53:找到类型通用整数==>在a-ngelfu.ads:24调用“Log”例如在线482
+1,您是对的。我只修正了编译错误,没有意识到这一点。 – Xandy 2010-02-11 18:50:57