From: | Volker Barthelmann |
Date: | 02 Dec 99 at 03:27:51 |
Subject: | Re: Little maths problem |
From: Volker Barthelmann <volker@vb.franken.de>
[I don't have the original message any more, so please tell me if I'm
misunderstanding the problem.]
On Sun, 28 Nov 1999, Alastair M. Robinson wrote:
> > I have a value stored in a FLOAT that lies in the range 0-500000.
> <snip>
> > FLOAT f; f=somevalue;
> > f=500000-f; f*=f; f=(500000*500000)-f; f/=(500000*500000);
>
> I *love* maths problems, so imagine my disappointment when I found out that
> yours is actually a compiler problem!
>
> > Am i barking up the wrong tree.
>
> No, your reasoning is fine. All you need to do is write 500000.0 instead of
> 500000, otherwise the compiler gets the floats and ints mixed up.
> (At least, VBCC did when I tried your code!)
Er..this is not a compiler problem and vbcc is not mixing anything up.
It's the way how C works. The type a subexpression is evaluated depends
only on the operands of this subexpression, not on any operands in
different subexpressions.
Volker