使用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