Re: CDC Floating point = tests?



stocksami@xxxxxxxxxxxxx <stocksami@xxxxxxxxxxxxx> wrote:

On the old CDC machines running EKS you could use a regular if test to
see if two floating point values were equal, and it worked! I've
ported lots of code from EKS to other platforms and I've had to change
those lines of codes many many times.

I'm not sure exactly what your question really is. First, it sounds as
though you are surprised that testing floating point values for equality
can ever work. Well, it can. No special compiler tricks are necessary.
It is a simple operation that any Fortran compiler can do - and can do
correctly. I half wonder whether you might be seeing warning messages
from other compilers and overreacting to them. There are compilers that
will give you a warning for every attempt to compare two floating point
numbers for equality. That is only a warning, suggesting that this might
be a bad idea. It does *NOT* mean that it won't work; it will work.
Whether it is a good idea is a separate matter. Sometimes it is a
perfectly fine idea. Other times it is not.

The other posters have concentrated on the question of why it is
sometimes not a good idea, what can be done about those cases, why the
results of the problematic cases can vary among compilers, and related
matters.

But your question seemed to me to have a hint of suprise that any code
could ever work with floating point equality tests. Perhaps I misread
that hint, but I thought it worth clarifying the sim ple case first. I
have seen people who had perfectly valid and "safe" code, but thought
that they had to change it because the compiler gave them a warning
message. The people did not understand the distinction between a warning
and an error. That might not be the case for you, in which case I
apologize for making a "trivial" point. But it seemed worth making just
in case.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.



Relevant Pages

  • Re: CDC Floating point = tests?
    ... though you are surprised that testing floating point values for equality ... No special compiler tricks are necessary. ... I half wonder whether you might be seeing warning messages ... MODULE PROCEDURE Compare_Real_Single ...
    (comp.lang.fortran)
  • Re: CDC Floating point = tests?
    ... though you are surprised that testing floating point values for equality ... No special compiler tricks are necessary. ... I half wonder whether you might be seeing warning messages ...
    (comp.lang.fortran)
  • Re: assert( x > 0.0 && 1 && x == 0.0 ) holding
    ... by equality of floating point numbers. ... Can you get your compiler to generate ... quite zero. ...
    (comp.lang.c)
  • Re: Why INFINITE loop in a thread occupy so much CPU time??
    ... With the attendant warning about the constant expression. ... This is a common programming technique. ... Good programming practice would consist of using the compiler at ... One can write 'bool' in C++ but not C. ...
    (microsoft.public.vc.mfc)
  • Re: help needed please!
    ... But some compilers like to give you a warning ... Each warning a compiler can give you is important when you not ... but you may use flages to handle flags to handle flags when you ... >> stdout is line bufferd and until one or both of the following cases is ...
    (comp.lang.c)