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


Groups > comp.lang.python > #38955

Re: python math problem

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joel.goldstick@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'line:': 0.07; 'length)': 0.09; 'rounding': 0.09; 'cc:addr:python-list': 0.10; 'subject:python': 0.11; '(x,': 0.16; 'angle': 0.16; 'binary,': 0.16; 'coordinates': 0.16; 'multiples': 0.16; 'string': 0.17; 'wrote:': 0.17; 'string,': 0.17; 'feb': 0.19; 'math': 0.20; 'trying': 0.21; 'subject:problem': 0.22; 'cc:2**0': 0.23; '15,': 0.23; 'errors': 0.23; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'values': 0.26; 'message-id:@mail.gmail.com': 0.27; 'url:mailman': 0.29; 'fri,': 0.30; 'point': 0.31; 'url:python': 0.32; 'skip:- 10': 0.32; 'url:listinfo': 0.32; 'getting': 0.33; 'received:google.com': 0.34; 'skip:: 10': 0.35; 'doing': 0.35; 'expected': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'url:org': 0.36; '(i.e.': 0.36; 'scientific': 0.36; 'should': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:( 30': 0.38; 'instead': 0.39; 'end': 0.40; 'url:mail': 0.40; 'times': 0.63; 'email addr:gmail.com': 0.63; '180': 0.84; '2013': 0.84; 'notion': 0.84; 'joel': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=YyLPVsaHH9CZ5mlK/CslWd7UbhtBmAhmkM0RHyT1SVA=; b=K3yEkfaY5BdnXpP4yhXZeDSWI2gaBdDUmyi5b/Xw1gOv1vE0irL6nKoMFTB5INAsSc 8dgm1PQEyMizwnGHV1ix90RXoWAilRKOSEHuEGGUVvu60ufVk46KFbNF6J+dBEikDvhb M7XagU5M7uD+VXxMq7VqmGBIOJSODV7d0mDXG7xIFAqPB07DirUmFndfIUUhtwZUAxYr Q9wT8rTKcELTcnsnbxSRSIhZH5GsjwxIrkG6dV0JC5PkfCgl4jI0BOr5qxLMdif1iICS byUdOxEzgVL+2i84G8v19JbwePYHO36yRWErD5Sw2C+RacWPb54MW4H1rFIomz3Jj/47 rdqg==
MIME-Version 1.0
X-Received by 10.220.9.3 with SMTP id j3mr4772946vcj.56.1360957769846; Fri, 15 Feb 2013 11:49:29 -0800 (PST)
In-Reply-To <kfm2t8$9ru$1@ger.gmane.org>
References <kfm2t8$9ru$1@ger.gmane.org>
Date Fri, 15 Feb 2013 14:49:29 -0500
Subject Re: python math problem
From Joel Goldstick <joel.goldstick@gmail.com>
To Kene.Meniru@illom.org
Content-Type multipart/alternative; boundary=bcaec54ee0146d0e9e04d5c8acda
Cc "python-list@python.org" <python-list@python.org>
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.1842.1360957772.2939.python-list@python.org> (permalink)
Lines 95
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360957772 news.xs4all.nl 6982 [2001:888:2000:d::a6]:38313
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38955

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, Feb 15, 2013 at 2:39 PM, Kene Meniru <Kene.Meniru@illom.org> wrote:

> I am trying to calculate the coordinates at the end of a line. The length
> and angle of the line are given and I am using the following formula:
>
> x = (math.sin(math.radians(angle)) * length)
> y = (math.cos(math.radians(angle)) * length)
>
> The following are sample answers in the format (x, y) to the given
> length/angle values of the line:
>
> 120/0  = (0.0, 25.0)
> 120/89 = (24.9961923789, 0.436310160932)
> 120/90 = (25.0, 1.53075794228e-15)
>

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.

> 120/91 = (24.9961923789, -0.436310160932)
>
> Why am I getting a string number instead of the expected answer  for 120/90
> which should be (25.0, 0.0). This happens at all multiples of 90 (i.e. 180
> and 270)
>
> --
>
> Kene
> ::::::::::::::::::
> KeMeniru@gmail.com
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com

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


Thread

Re: python math problem Joel Goldstick <joel.goldstick@gmail.com> - 2013-02-15 14:49 -0500

csiph-web