Mail Archives: djgpp/1996/02/10/06:45:40
>
> Ignore the last missive -- =)
> I just discovered the cause.
>
> Given the following:
>
> #define X 5
> #define Y 6
>
> float z;
>
> z = X / Y * 5.6;
The above is a programming error. Nowhere is written that
C does automatic casting. The correct casting always
has done by the programmer him/herself.
Float constants in expressions are always treated as double in C
and results are double as well.
Defining the result of a float calculation as float may be dangerous
as well since the result may overfloat the range of a float.
>
> Turbo C++ evaluates X and Y as integers (!) which is what caused my
> acos() domain errors. However, GCC 2.7.2 (DJGPP 2.0) _correctly_
> evaluates the above; both X and Y seem to be treated as floats. "Fixing"
> the defines like so:
>
> #define X 5.0
>
> or
>
> #define X (float)5
>
> now, which is the ANSI-defined behavior, that of Turbo C, or that of
> DJGPP? (the evaluate-as-integer problem appeared using both Turbo C 2.0
> and Turbo C++ 3.0)
>
> Thanks,
>
> /----------------------------------------------------------------------------\
> | Orlando A. Andico "I have no concept of time, other than |
> | oandico AT eee DOT upd DOT edu DOT ph it is flying." -- Alanis Morissette |
> \----------------------------------------------------------------------------/
>
>
--Chris Christoph P. U. Kukulies kuku AT gil DOT physik DOT rwth-aachen DOT de
- Raw text -