Re: perl style: can I combine two steps into one?

From: John Bokma (postmaster_at_castleamber.com)
Date: 02/06/05


Date: 6 Feb 2005 19:34:50 GMT

RedGrittyBrick wrote:

> John Bokma wrote:

[ snip ]

> Since I was raised on FORTRAN, it is deeply ingrained in me that one
> should never test floating point numbers for equality. So I tend to feel
> more comfortable writing "x >= 10" than "x = 10" where x is being
> incremented in some fashion.

It wasn't a float.

> Unfortunately this aversion also applies
> inappropriately to integer comparisons.
>
> Perhaps one should write
> last if i == 10;
> die "Too many impossible things before breakfast." if i > 10;

As silly as:

die "Panic" if int( i ) != i;

if i is already int.

If i "suddenly" becomes float, it's quite weird to rely on the fact that
you already took care of i possible becoming float.

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


Relevant Pages

  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... value for equality is rather likely not to work - you have to round ... I find top-posting a PITA - I need the question to understand ... that usenet etiquette wasn't made up just on a whim to "push down ...
    (comp.lang.c)
  • Re: Possible compiler bug?
    ... > But the float comparison could be the reason since calculated float values ... > stored in a 64 bit register you can lose some digits and successive ... >> equality. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Possible compiler bug?
    ... > But the float comparison could be the reason since calculated float values ... > stored in a 64 bit register you can lose some digits and successive ... >> equality. ...
    (microsoft.public.dotnet.csharp.general)
  • Re: please comment
    ... >> float div ... #include and then initialize c: ... one should not test floating point numbers for equality. ... code a direct comparison to zero is the correct thing to do, ...
    (comp.lang.c)