Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38964
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: python math problem |
| Date | 2013-02-15 17:25 -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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1851.1360967128.2939.python-list@python.org> (permalink) |
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 | Next — Next in thread | Find similar | Unroll 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