This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

float substraction error

Has anyone had any problems substracting floats? I have the following code:
(C166 V4.23 compiler)

float dummy, test1, test2;

test1 = 1.0e10;
test2 = 1.1e10;
dummy = test2 - test1;

for some reason dummy comes out as
1.000001e9

I've tried declaring them as doubles and get the same result.


DS

Parents
  • 1.000001e9 is close enough to 1.0e9, isn't it? If it's not for you, move to double. If FLOAT64 directive is not specified, THE C166 COMPILER uses single-precision floating-point arithmetic even if the double keyword is used in the C source file. Go to C166 in the target settings and check the Double-precision Floating Point option.

    - Mike

Reply
  • 1.000001e9 is close enough to 1.0e9, isn't it? If it's not for you, move to double. If FLOAT64 directive is not specified, THE C166 COMPILER uses single-precision floating-point arithmetic even if the double keyword is used in the C source file. Go to C166 in the target settings and check the Double-precision Floating Point option.

    - Mike

Children
No data