小编eri*_*aht的帖子

定点类型不能正确相乘

我是Ada的新手,并且一直在试用定点"delta"类型.具体来说,我创建了一个32位delta类型范围0.0 .. 1.0.但是,当我尝试对某些值进行平方时,我得到一个CONSTRAINT_ERROR.据我所知,这不应该发生在我指定的范围内.此错误的阈值似乎是sqrt(1/2).我正在使用MinGW-w64版本4.8.0的GNAT.

测试代码(所有代码都gnatmake <file>以没有警告/错误的形式编译):

types.ads:

pragma Ada_2012;

with Ada.Unchecked_Conversion;
with Ada.Text_IO;

package Types is
    type Fixed_Type is delta 1.0 / 2**32 range 0.0 .. 1.0
        with Size => 32;
    type Modular_Type is mod 2**32
        with Size => 32;
    function Fixed_To_Mod is new Ada.Unchecked_Conversion(Fixed_Type, Modular_Type);
    package MIO is new Ada.Text_IO.Modular_IO(Modular_Type);
    package FIO is new Ada.Text_IO.Fixed_IO(Fixed_Type);
end Types;
Run Code Online (Sandbox Code Playgroud)

specifics.adb:

pragma Ada_2012;

with Ada.Text_IO;

with Types; use Types;

procedure Specifics is
    package TIO renames Ada.Text_IO;

    procedure TestValue(val: in …
Run Code Online (Sandbox Code Playgroud)

fixed-point ada multiplication

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

标签 统计

ada ×1

fixed-point ×1

multiplication ×1