The following code prints TRUE
that means 0.0191*0.0191
is evaluating to 0.0003
and 0.0192*0.0192
is evaluating to 0.0004
. However:
0.0191*0.0191 = 0.00036481
0.0192*0.0192 = 0.00036864
Had the rounding happened at the threshold of 0.00035
, the corresponding threshold for square root should have been 0.0187
.
If I change the delta to 10.0**(-5)
, this is not the case.
So my question is "How rounding of fixed-point calculation works in this situation?"
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
type T is delta 10.0**(-4) range 0.0 .. 10.0;
X1 : T := 0.0191;
X2 : T := 0.0192;
Y : T := 0.0004;
B : Boolean;
begin
B := (X1 * X1 = Y - T'Delta) and (X2 * X2 =Y);
Put_Line(B'Image);
end Main;