On Sunday, July 24, 2005 at 6:11 PM, Ken Barker wrote:
> 
> What kind of post is this?
> 
> I do not see that anything was added at all.  Give us all a 
> break - don't 
> bother - whatever your intentions.
> 


well, don't you feel stupid now?



> 
> At 06:35 PM 7/24/2005, $Bill Luebkert wrote:
> >John Deighan wrote:
> > > At 02:20 PM 7/24/2005, Ed Chester wrote:
> > >
> > >
> > >>John Deighan::
> > >>
> > >>>Is there a safe way to compare 2 floating point numbers in Perl? 
> > >>>[snip] My debugger says that they're both '630.24' 
> [snip] However, 
> > >>>the == test fails and the != test succeeds
> > >>
> > >>can you post code with the comparison == that fails ?
> > >>if the debugger says they're the same, they're very very probably 
> > >>the same. are you sure the variable (or whatever) you're 
> giving to 
> > >>== are really  what you want them to be?
> > >>there are lots of ways to compare numbers, right down to 
> looping over 
> > the bits
> > >>and logically
> > >>XNORing them.
> > >
> > >
> > > Sorry about the lack of sample code, but I know that 
> people who work 
> > > with floating point numbers know about this problem, and I was 
> > > wondering what the best solution was. Here is sample code with 
> > > output. Note that I'm not formatting the output or rounding or 
> > > anything - just printing out the contents of the 2 variables.
> > >
> > > my $sum1 = -237.15;
> > > my $sum2;
> > > $sum2 += -26.35;
> > > $sum2 += -26.35;
> > > $sum2 += -26.35;
> > > $sum2 += -26.35;
> > > $sum2 += -26.35;
> > > $sum2 += -26.35;
> > > $sum2 += -26.35;
> > > $sum2 += -26.35;
> > > $sum2 += -26.35;
> > >
> > > print("sum1 = $sum1\n");
> > > print("sum2 = $sum2\n");
> > > if ($sum1 == $sum2) {
> >
> >You could try something like:
> >
> >   if (abs ($sum1 - $sum2) < .0001) {
> >
> > >          print("EQUAL\n");
> > >          }
> > > else {
> > >          print("NOT EQUAL\n");
> > >          }
> > >
> > > OUTPUT:
> > >
> > > sum1 = -237.15
> > > sum2 = -237.15
> > > NOT EQUAL
> > >
> > >
> > > _______________________________________________
> > > Perl-Win32-Users mailing list 
> > > [email protected]
> > > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> > >
> >
> >
> >--
> >   ,-/-  __      _  _         $Bill Luebkert    
> Mailto:[EMAIL PROTECTED]
> >  (_/   /  )    // //       DBE 
> Collectibles    Mailto:[EMAIL PROTECTED]
> >   / ) /--<  o // //      Castle of Medieval Myth & Magic 
> > http://www.todbe.com/
> >-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My 
> Perl/Lakers stuff)
> >_______________________________________________
> >Perl-Win32-Users mailing list 
> [email protected]
> >To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> 
> _______________________________________________
> Perl-Win32-Users mailing list 
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> 

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to