如何在 Ada 中将整数转换为浮点数,反之亦然?

How to transform integer to float and vice-versa in Ada?

是否有某种已实现的函数允许将整数转换为浮点数,反之亦然?

我设法编写了一个将整数转换为浮点数的简短函数:

function Transform(First: Integer) return Float is
    A: Integer := First;
    B: Float := 0.0;
begin
    For_Loop:
    for I in Integer range 1 .. A loop
        B := B + 1.0;
    end loop For_Loop;
    return B;
end Transform;

但我不知道如何从 FloatInteger

阿达可以做到explicit type conversions

with Ada.Text_IO; use Ada.Text_IO;
procedure Convert is
  A: Integer:= 4;
  B: Float;
  C: Float := 6.8;
  D: Integer;
begin
  B := Float(A);
  Put_Line(Float'Image(B));

  D:= Integer(C);
  Put_Line(Integer'Image(D));
end Convert;

Barnes 说要从 Integer 转换为 Float,您应该乘以 1.0。 as root Real * Root Integer is allowed and returns the root Real.