跳轉到內容

Ada 程式設計/分隔符/**

來自華夏公益教科書,開放的書籍,開放的世界

Ada. Time-tested, safe and secure.
Ada。經時間考驗,安全可靠。

運算子

[編輯 | 編輯原始碼]

標準運算

[編輯 | 編輯原始碼]

算術冪

[編輯 | 編輯原始碼]

“**”運算子定義為所有數字型別算術冪。

function "**" (Left : T; Right : Integer) return T;
A : constant Float   := 5.0 ** 2;  -- A is now 25.0
B : constant Integer := 5 ** 2;    -- B is also 25
工作示例
[編輯 | 編輯原始碼]
檔案: operator_power.adb (檢視, 純文字, 下載頁面, 瀏覽全部)
with Ada.Text_IO;

procedure Operator_Power is
   A : constant Float   := 5.0 ** 2;  -- A is now 25.0
   B : constant Integer := 5 ** 2;    -- B is also 25

   package T_IO renames Ada.Text_IO;
   package F_IO is new  Ada.Text_IO.Float_IO (Float);
   package I_IO is new  Ada.Text_IO.Integer_IO (Integer);

begin
   T_IO.Put ("A = ");
   F_IO.Put (
      Item => A,
      Fore => 3,
      Aft  => 1,
      Exp  => 0);
   T_IO.New_Line;
   T_IO.Put ("B = ");
   I_IO.Put (
      Item  => B,
      Width => 3,
      Base  => 10);
   T_IO.New_Line;
end Operator_Power;

另請參閱

[編輯 | 編輯原始碼]

華夏公益教科書

[編輯 | 編輯原始碼]

Ada 95 參考手冊

[編輯 | 編輯原始碼]

Ada 2005 參考手冊

[編輯 | 編輯原始碼]



Ada 運算子
and and then > + abs &
or or else >= - mod
xor = < * rem in
not /= <= ** / not in
華夏公益教科書