小编Asc*_*lar的帖子

如何仅使用 Ada 中的 Image 功能来控制显示的小数位数?

我在 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)

numbers decimal ada display

3
推荐指数
2
解决办法
154
查看次数

如何使 Ada 数学函数使用双精度(长浮点数)变量?

Ada 的标准数学函数如 sin、cos、*、/ 等仅支持 Float 类型变量作为输入和输出。是否可以让这些函数处理输入和输出变量的双精度或 long_float?

math double ada

1
推荐指数
1
解决办法
69
查看次数

标签 统计

ada ×2

decimal ×1

display ×1

double ×1

math ×1

numbers ×1