我在 Ada 中有以下代码行,
Put_Line ("Array of " & Integer'Image (iterations)
& " is " & Long_Float'Image (sum)
& " Time = " & Duration'Image(milliS) & timescale);
Run Code Online (Sandbox Code Playgroud)
sum 中的小数位数太长而无法显示(不适用于计算,因为 sum 计算需要长浮点数)。我知道 Ada 有使用前后显示小数的替代方法,而不使用 Image 函数,但在我切换到替代方法之前,我想知道 Image 是否有选项或其他显示小数的技术。Image 函数有显示小数的选项吗?是否有一种技术可以缩短 Long_Float 的小数位数仅用于显示?
with Ada.Numerics;
with Ada.Text_IO; use Ada.Text_IO;
procedure Images is
sum : Standard.Long_Float;
Pi : Long_Float := Ada.Numerics.Pi;
type Fixed is delta 0.001 range -1.0e6 .. 1.0e6;
type NewFixed is range -(2 ** 31) .. +(2 ** 31 - 1);
type Fixed2 …Run Code Online (Sandbox Code Playgroud) Ada 的标准数学函数如 sin、cos、*、/ 等仅支持 Float 类型变量作为输入和输出。是否可以让这些函数处理输入和输出变量的双精度或 long_float?