Вопрос

Reading this http://en.wikibooks.org/wiki/Ada_Programming/Types/delta has got me wondering what the limit value of delta is.

For example

delta 127 range 0..1_000_000;

needs one byte to hold the delta value.

But

delta 0.0000000001 range 0..1;

would need more bytes, right?

So is there a limit to delta? Surely we can't go on indefinitely to smaller increments?

In the above link it says

If the compiler accepts your fixed point type definition, it guarantees that values represented by that type will have at least the degree of accuracy specified (or better). If the compiler cannot support the type definition (e.g. due to limited hardware) then a compile-time error will result.

Это было полезно?

Решение

The compiled code doesn't hold the Delta value anywhere; stored values of the type are scaled, so the required size corresponds to the range divided by the Small (remembering that if Delta isn't a power of two you will need to specify Small to be the same as Delta).

For GNAT, it turns out that there is a minimum supported value of Delta, and that there's a maximum Size for objects of the type: on Mac OS X (Intel),

Small_Delta : constant := 2.0 ** (-127);
Small_Bound : constant := 2.0 ** (-64);
type T1 is delta Small_Delta range -Small_Bound .. Small_Bound;

fails with

"T1'Small" too small, minimum allowed is 2.0**(-80)

and

Larger_Delta : constant := 2.0 ** (-64);
Larger_Bound : constant := 2.0;
type T2 is delta Larger_Delta range -Larger_Bound .. Larger_Bound;

fails with

size required (67) for type "T2" too large, maximum allowed is 64

(I'm not sure why 67, not 65!)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top