Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange compilation error with gnat on fixed point declaration

Compilation fails with the F6 declaration below :

type F3 is delta 2.0**(-4) range 0.0 .. ((2.0**8)-1.0)*2.0**(-4);    -- byte  16#f.f#;
for f3'size use 8;

type F4 is delta 2.0**(-8) range 0.0 .. ((2.0**16)-1.0)*2.0**(-8);   -- word 16#ff.ff#
for f4'size use 16;

type F5 is delta 2.0**(-16) range 0.0 .. ((2.0**32)-1.0)*2.0**(-16); -- dword 16#ffff.ffff#
for f5'size use 32;

type F6 is delta 2.0**(-32) range 0.0 .. ((2.0**64)-1.0)*2.0**(-32); -- ldword 16#ffff_ffff.ffff_ffff#
for f6'size use 32;

Same failure both on linux64/v8.0.3 and on learn.adacore.com.

edit error message is "size required (65) for type "f6" too large, maximum allowed is 64"

edit add 'size instructions / intended upper bound in hex

edit added fixed type freeze trace below

loval -16#0.FF#E1, hival 16#0.FF#E1, Actual_Size  9
loval 0.0, hival 16#0.FF#E1, Actual_Size  8

loval -16#0.FFFF#E2, hival 16#0.FFFF#E2, Actual_Size  17
loval 0.0, hival 16#0.FFFF#E2, Actual_Size  16

loval -16#0.FFFF_FFFF#E4, hival 16#0.FFFF_FFFF#E4, Actual_Size  33
loval 0.0, hival 16#0.FFFF_FFFF#E4, Actual_Size  32

loval -16#0.FFFF_FFFF_FFFF_FFFF#E8, hival 16#0.FFFF_FFFF_FFFF_FFFF#E8, Actual_Size  64
loval 0.0, hival 16#0.FFFF_FFFF_FFFF_FFFF#E8, Actual_Size  63
like image 213
wondering-if Avatar asked Jan 01 '23 10:01

wondering-if


1 Answers

The base problem is that your GNAT does not support fixed point types with a size more than 64 bits, as the error message states. And F6 seems to require 65 bits. This happens because for fixed point types, the reference manual states:

The base range (see 3.5) of a fixed point type is symmetric around zero, except possibly for an extra negative value in some implementations.

This means that the base range of type F6 also includes the symmetric negative numbers and thus requires a sign bit. This is why, the representation of the base range needs 65 bits instead of 64 bits as you'd expect.

Now the manual also states that

An ordinary_fixed_point_definition also defines a constrained first subtype of the type

So F6 is a subtype of the base type requiring 65 bits. Due to the range constraints of F6, it would only need 64 bits of representation. As F6 is the first subtype, we may constrain its size with an attribute definition clause:

for F6'Size use 64;

This forces the compiler to try and use only 64 bits for representation. I am unsure whether this solves your problem; it could be that you cannot circumvent the error this way since the compiler requires a representible base type.

like image 88
flyx Avatar answered Jan 03 '23 00:01

flyx