【问题标题】:Ada95: How to use Float in Exponent?Ada95:如何在指数中使用浮点数?
【发布时间】:2017-10-22 10:48:26
【问题描述】:

我尝试过的:

 function Get_T(I : in Integer)
                return Float is
    T:Float;
    M:Float:=Float(I);
  begin
    T:=40.0*0.5**((60.0-M)/20.0);  -- FLOAT NOT ACCEPTED IN EXPONENT
    return T;
  end Get_T;

我需要一个特殊的包裹吗?我一直在看 Ada.Numerics.Generic_Elementary_Functions 但我不知道如何使用它。

【问题讨论】:

    标签: floating-point ada exponent


    【解决方案1】:

    您可以使用Ada.Numerics.Elementary_Functions 包中定义的幂运算符:

    With Ada.Numerics.Elementary_Functions;
    
    function Get_T(I : in Integer) return Float is
        use Ada.Numerics.Elementary_Functions;
        T: Float;
        M: Float := Float(I);
    begin
        T := 40.0 * 0.5 ** ((60.0 - M) / 20.0);
        return T;
    end Get_T;
    

    【讨论】:

    • 你可以使用Ada.Numerics.Elementary_Functions,这是Generic_Elementary_Functions已经为Float实例化了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多