Re: i can't understand behaviour of if statement
From: Chris Torek (nospam_at_torek.net)
Date: 03/28/04
- Next message: Simon Biber: "Re: Portability question"
- Previous message: THE FAITHFUL: "Re: @@@ TEMPTATION - A MUST SEE @@@"
- In reply to: Paula: "i can't understand behaviour of if statement"
- Next in thread: Paula: "Re: i can't understand behaviour of if statement"
- Reply: Paula: "Re: i can't understand behaviour of if statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Mar 2004 17:51:33 GMT
In article <news:7f1e3c62.0403280850.77dca66a@posting.google.com>
Paula <pcoelho@usp.br> writes:
>printf("z= %f, alfa= %f",&z,&alfafe);
>if (z == 0.008) {printf("==== here z"); <...>}
>if (alfafe == 0.5) {printf("**** here alfa"); <...>}
Others have already answered the most likely source of the problem
(floating point rounding -- incidentally, you *might* have more
success using 0.008f instead of 0.008, but this is still not a good
idea in general).
I will add that this is probably *not* the actual code you are
using, because the unary "&" operators in the printf() call are
not appropriate here and would most likely have resulted in bizarre
values for "z" and "alfa". (It also seems a bit odd to name the
variable "alfafe" in the code and "alfa" in the printf text, but
this, at least, is not something that would produce bizarre behavior.)
Bugs can be caused by niggly little single-character typos, so it
is often unwise to post something other than an actual program.
Of course, if the program is huge, posting it unchanged may *also*
be unwise. :-) ("... advice is a dangerous gift, even from the
wise to the wise, and all courses may run ill.") In this case,
probably there was no loss, but in general, posting a small program
that shows the problem, or a cut-and-paste -- as opposed to retyping
-- of the code that exhibits the problem, is usually your best bet.
-- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: forget about it http://web.torek.net/torek/index.html Reading email is like searching for food in the garbage, thanks to spammers.
- Next message: Simon Biber: "Re: Portability question"
- Previous message: THE FAITHFUL: "Re: @@@ TEMPTATION - A MUST SEE @@@"
- In reply to: Paula: "i can't understand behaviour of if statement"
- Next in thread: Paula: "Re: i can't understand behaviour of if statement"
- Reply: Paula: "Re: i can't understand behaviour of if statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|