Ada : Float literals vs float variables

I am seeing some strange behaviour when rounding floating point numbers in my Ada code.

I understand that floats are not reliable, and that sometimes they aren't represented exactly.

My question is around why it would matter if you store the value in a variable first.

float'rounding(8.9 / 0.2)

the above comes out as 45, which seems to make sense, 8.9 / 0.2 = 44.5 then round away from zero. (I also tried casting each number to a float to make sure there wasnt some type difference)

but then

a : float : 8.9;
b : float : 0.2;
float'rounding(a / b)

this time it comes out as 44. which means that a / b = 44.4999999 then round down.

Why does saving the values in a variable change the outcome of the calculation when its all the same types?!

Any insight would be amazing!



from Recent Questions - Stack Overflow https://ift.tt/3yGfxe3
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)