Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Float precision and float equality
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Carl Banks  
View profile  
 More options Dec 6 2009, 5:54 pm
Newsgroups: comp.lang.python
From: Carl Banks <pavlovevide...@gmail.com>
Date: Sun, 6 Dec 2009 14:54:37 -0800 (PST)
Local: Sun, Dec 6 2009 5:54 pm
Subject: Re: Float precision and float equality
On Dec 6, 11:34 am, Anton81 <gerenu...@googlemail.com> wrote:

> I do some linear algebra and whenever the prefactor of a vector turns
> out to be zero, I want to remove it.

> I'd like to keep the system comfortable. So basically I should write a
> new class for numbers that has it's own __eq__ operator?
> Is there an existing module for that?

I highly recommend against it; among other things it invalidates the
transitive property of equality:

"If a == b and b == c, then a == c."

It will also make the number non-hashable, and have several other
negative consequences.  Plus, it's not something that's never
foolproof.  What numbers are close enought to be condidered "equal"
depends on the calculations.

(I remember once struggling in a homework assignment over seemingly
large discrepancies in a calculation I was doing, until i realized
that the actual numbers were on the scale of 10**11, and the
difference was around 10**1, so it really didn't matter.)

Carl Banks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.