-3

I'v ran into another anomaly:

float T = 19.0 / 99.0;
float moo = (99.0 * T) - 19.0;

as expected, T = 0.191919, however 'moo' is meant to be 0 but instead is 7.450586. I can only presume some form of casting is once again required somewhere.

Dead_S
  • 115
  • 1
  • 2
  • 6

2 Answers2

0

Change your code to this and you will get 0 on moo

float T = 19.0f / 99.0f; float moo = (99.0f * T) - 19.0f;

Also the value on moo without this is not 7.45, it is 7.45058e-08 which is almost zero.

exs
  • 122
  • 1
  • 4
0

Since any floating point numbers are represented in 2's complement notation in c++.you will usually get approximate values , while manipulating floating point values .So 7.450586e-008 is exact behaviour . If you need more precision use double.

mystic_coder
  • 462
  • 2
  • 10