floating-point - 阿达95 : How to use Float in Exponent?

标签 floating-point ada exponent

我尝试过的:

 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,但我不确定如何使用它。

最佳答案

您可以利用 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;

关于floating-point - 阿达95 : How to use Float in Exponent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46873186/

相关文章:

谁能帮我写一下我的 C 代码吗?

oop - 从 Ada 中的基类调用重写的方法

c++ - cuda 数学函数 norm3df 是否溢出?

java - 处理 - 将字符串解析为 float NullPointerException 时抛出

null - 从 Ada 中的地址 0x0 读取

android - 如何在自定义键盘上添加指数(上标)符号?

javascript - 如何使用 Math.pow() 来求解复利?

performance - 代码的递归求幂

C : Strange error when using float and double

ada - 使用 Ravenscar 在嵌入式设备上进行多任务处理