asn1scc generated code includes the adasn1rtl.ads file, which contains this:
function Asn1Real_Equal (Left, Right : Asn1Real) return Boolean is
(if Left = Right then True elsif Left = 0.0 then Right = 0.0
elsif (Left > 0.0 and Right < 0.0) or (Left < 0.0 and Right > 0.0) then
False
elsif abs (Left) > abs (Right) then abs (Right) / abs (Left) >= 0.99999
else abs (Left) / abs (Right) >= 0.99999);
GNAT 15.2.0 complains about the parentheses around abs
GNAT already emits a style warning when redundant parentheses appear inside
logical and short-circuit operators. A similar warning will be soon emitted for
unary operators as well. This patch removes the redundant parentheses to avoid
build errors.
I’d probably end up doing something like this for readability:
function Asn1Real_Equal (Left, Right : Asn1Real)
return
Boolean
is
(if Left = Right then
True
elsif Left = 0.0 then
Right = 0.0
elsif
Left > 0.0 and Right < 0.0 or
Left < 0.0 and Right > 0.0
then
False
elsif abs (Left) > abs (Right) then
abs (Right) / abs (Left) >= 0.99999
else
abs (Left) / abs (Right) >= 0.99999);
However, although the precedences are equal, and, or and xor cannot be mixed up in an expression without using parentheses (unlike + and - for instance).
EDIT I clearly haven’t had enough coffee and it’s impacting my reading comprehension, I just realized that it’s complaining about using them around abs. Just disregard my response. I’ll leave my posts up as a monument to my shame.
Side note: when building the bare_runtime crate using gnat15 you also have to remove all of the redundant parentheses since style warnings are treated as errors for runtime systems. Guess how I know
I would guess Ada does better here but I never rely on precedence (since before the Linux kernel rules added that you shouldn’t) which can be the cause of bugs through unnecessary complexity. I remove them when the Gnat compiler assures me it’s all good though with some knee jerk annoyance that’s fading.