Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38964

Re: python math problem

Path csiph.com!usenet.pasdenom.info!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.023
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rounding': 0.09; 'zero.': 0.09; 'subject:python': 0.11; '0.0,': 0.16; 'binary,': 0.16; 'equality.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.17; 'string,': 0.17; 'feb': 0.19; 'math': 0.20; 'subject:problem': 0.22; 'errors': 0.23; 'testing': 0.24; 'header:X-Complaints-To:1': 0.28; 'fri,': 0.30; 'point': 0.31; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'doing': 0.35; 'received:org': 0.36; 'compare': 0.36; 'scientific': 0.36; 'test': 0.36; 'should': 0.36; 'charset:us- ascii': 0.36; 'possible': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'times': 0.63; 'more': 0.63; '2013': 0.84; 'notion': 0.84; 'teachings': 0.84; 'dennis': 0.91; 'joel': 0.91; 'successful.': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: python math problem
Date Fri, 15 Feb 2013 17:25:20 -0500
Organization > Bestiaria Support Staff <
References <kfm2t8$9ru$1@ger.gmane.org> <CAPM-O+wEJBOp62m_H9dvp=orS-DxWkuJtBLUc6DMC91aDrv85Q@mail.gmail.com> <kfm5fq$1lr$2@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host adsl-76-253-102-210.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 3.3/32.846
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1851.1360967128.2939.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360967128 news.xs4all.nl 6990 [2001:888:2000:d::a6]:36795
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38964

Show key headers only | View raw


On Fri, 15 Feb 2013 15:23:29 -0500, Kene Meniru <Kene.Meniru@illom.org>
declaimed the following in gmane.comp.python.general:

> Joel Goldstick wrote:
> 
> > 
> > This is not a string, it is scientific notion for 1.53... times 10 to the
> > -15th power.  Because of rounding errors caused by doing floating point
> > math on in binary, you get a very small number instead of 0.
> > 
> 
> I was just doing some testing and it was not equating to zero. Perhaps if I 
> rounded it up I may be more successful.

	Classical CompSci teachings when working with floating point numbers
is to NEVER compare for equality. Instead one should compare against
some epsilon:

	if x == y:	#don't do

	if abs(x - y) < epsilon:	#do this

	In your situation, "y" would be 0.0, so the test condenses to

	if abs(x) < epsilon:

and a possible epsilon may be 1.0E-14

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: python math problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-15 17:25 -0500
  Re: python math problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-16 15:49 +1100
    Re: python math problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-16 13:56 -0500

csiph-web