acsl-language / acsl

Sources for the ANSI/ISO C Specification Language manual
Other
49 stars 8 forks source link

Notation for non-finite floating-point values #78

Open maroneze opened 3 years ago

maroneze commented 3 years ago

Constants such as \plus_infinity, \minus_infinity and \NaN would be useful to have in ACSL.

Currently, specifications dealing with non-finite floating-point values must resort to using expressions such as 1.0f/0.0 or 0.0f/0.0, or they need to include math.h and rely on C99 macros such as INFINITY and NAN. The specifications become much less clear and may induce unnecessary dependency on libc headers.

vprevosto commented 3 years ago

A few points:

maroneze commented 3 years ago

Indeed, I couldn't find yet an example where ensures \result == \plus_infinity could not be replaced with ensures \is_plus_infinity(\result), or something similar (assuming the plugins handle this case precisely).

I think the only case where these constants seem necessary is when trying to use INFINITY/NAN in logic functions, e.g.:

logic float _infinity(ℤ x) = \plus_infinity;
logic float _nan(ℤ x) = \NaN;

With definitions such as the above, it is possible to use the same macros for INFINITY/NAN in logic functions as well as in other specifications, assuming the underlying C library (e.g. Frama-C's) uses a compatible definition for the macro.