Re: [C]

From: --Ben Horner-- (b-horner@WAITE.ADELAIDE.EDU.AU)
Date: 10/07/97


On Tue, 7 Oct 1997, Rich Chiavaroli wrote:

> Just a short question here about floats with ANSI C on AIX.
>
> This is an example of something I was trying to do.
>
> float a;
>
> a = 10 / 100;
>
> 'a' always comes back as 0. I've found a workaround for it but I was
> just curious if floats have to have a whole number part or if I was just
> doing something wrong. The formula was more complex but it would have
> produced a number between 0.01 and 0.99. On paper it should have anyway.
> But as soon as I divided by 100, the var became 0. I'm also curious if
> it can't be done like this, how is it supposed to be done...
>
> Thanks,
> Rich

No probs in c 10 and 100 are ints, so you must cast either 10 or 100 as a
float, ie few ways you can do it:
a = (float)10/100
a = 1.0*10/100  (1.0 being the float)
a = 10.0/100

note in these cases I thus have a float / int, c always takes highest one
so results = float.

Proky


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST