|
-
November 6th, 2001, 01:58 AM
#1
comparing floats
I am writing a program in C and I need to directly compare 2 floats. I can not use the == operator, so what can i do to compare them?
Brian, http://bpc007.cjb.net
-
November 6th, 2001, 02:38 AM
#2
Re: comparing floats
It's aint easy to answer a question without complete understanding of it ... But I try:
Why you can't use == operator ? If it's kinda test you always can substruct one float variable from other and check the sign of the result.
Please - rate answer if it helped you
It gives me inspiration when I see myself in the top list =)
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
[email protected] | ICQ:57404554 | http://soukhov.com
Russian Software Developer Network http://rsdn.ru
-
November 6th, 2001, 04:39 AM
#3
Re: comparing floats
Subtract the two values and see if the absolute value of the difference falls within a small tolerance level. If it does, then you can assume that the values are equal.
However, if you are writing a financial application using 'C', you should *never* use floats or doubles. Instead, you have to use integers, or get yourself a library that handles money values in exact amounts (a BCD library or some other type of large integer / fixed point library).
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|