We don't bite newbies here... much PerlMonks

### Re^2: eq vs ==

by oha (Friar)
 on Nov 11, 2009 at 09:59 UTC ( #806448=note: print w/replies, xml ) Need Help??

in reply to Re: eq vs ==

i would say that the correct way to compare use == with floating numbers is to not use floating numbers.

Update: as moritz said, i've wrongly used "compare" instead of "use =="

Replies are listed 'Best First'.
Re^3: eq vs ==
by moritz (Cardinal) on Nov 11, 2009 at 10:23 UTC
Would you care to explain how you would do that, in the general case?

For example in one of my programs I have a few matrices in which I put parameters, solve some equation systems and in the end I calculate a trace over some of these matrices, and as a result I get another matrix. In that final matrix the sum over all rows and all columns should be equal, modulo numeric errors.

How would I compare (or even compute) these sums without using or comparing floating point numbers?

Perl 6 - links to (nearly) everything that is Perl 6.
Re^3: eq vs ==
by oha (Friar) on Nov 11, 2009 at 11:01 UTC
not using float or not compare ==.

(or using abs(\$x-\$y) < \$epsilon as you already shown which is not the compare anyway)

I know my position is a bit strong, but using == on floats is going to make troubles, which depends on values, host, compiler, libc and so on. very hard to predict and replicate.

maybe a nice gift would be to have a warning?

Update: ops! i've replied to my node instead of moritz's 806454.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://806448]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2022-01-27 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In 2022, my preferred method to securely store passwords is:

Results (70 votes). Check out past polls.

Notices?