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


Groups > comp.lang.python > #51479

Re: Unexpected results comparing float to Fraction

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.036
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'interpreter': 0.05; 'say,': 0.05; 'float': 0.07; 'constructor': 0.09; 'rounds': 0.09; 'evaluates': 0.16; 'exactly?': 0.16; 'skip:6 30': 0.16; 'terribly': 0.16; 'two,': 0.16; 'wrote:': 0.18; 'skip:1 30': 0.19; 'fraction': 0.24; 'propose': 0.24; 'decide': 0.24; 'mon,': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'important.': 0.30; 'message-id:@mail.gmail.com': 0.30; 'division': 0.31; 'equal': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'choosing': 0.36; 'possible': 0.36; 'should': 0.36; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'ian': 0.60; 'choose': 0.64; 'sum': 0.64; 'here': 0.66; 'between': 0.67; 'jul': 0.74; 'float,': 0.84; 'subject:results': 0.91; 'obtained': 0.96; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=1sWRS7a+nLsYhaJf7fjlpcCSg6YbVhzh+AE70km6xvw=; b=Ve/58nBkZsDThA+pG7UqlalagKRAKebOXXPFfBsyMlRKHQ4Jm1zOEovACtK8YQyDGK kk6zZkTuzpHnmIlskssD6lQ2qmF4gt4qjmtk3jwHgWwk1xZdbxLcHpgNqq4pIcBTcaDX LrfEjcFrBstaRrKaXOHOmyE4zT77POKygdQx7gQf0lIp12a3KnacbfsAEn7bIsjBVetd 8rNrN6Nbbm/QYp1udLYSMmj6cNYhiNpqKvvUlrvRHAjKliyWJi+9I2NzbLb2FPuxh3+1 RyLJWTDSriIzaMqy/46e8UmbubPbfH2qDKHgVe+4otn7OI+88RSMf3srq+fPQCFlrcf6 xkOQ==
X-Received by 10.68.129.138 with SMTP id nw10mr37605910pbb.158.1375126451827; Mon, 29 Jul 2013 12:34:11 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <kt6b6a$s9p$1@dont-email.me>
References <51f68d9c$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F693B4.9000201@mrabarnett.plus.com> <CAPTjJmr=73v56-V69xnrDNsSV0SYDcOv5z6yG8+AtkjX2=XgFA@mail.gmail.com> <mailman.5244.1375116584.3114.python-list@python.org> <kt6b6a$s9p$1@dont-email.me>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Mon, 29 Jul 2013 13:33:31 -0600
Subject Re: Unexpected results comparing float to Fraction
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
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.5255.1375126463.3114.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375126463 news.xs4all.nl 15961 [2001:888:2000:d::a6]:45925
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51479

Show key headers only | View raw


On Mon, Jul 29, 2013 at 12:16 PM, Rotwang <sg552@hotmail.co.uk> wrote:
> On 29/07/2013 17:40, Ian Kelly wrote:
>> At the point where the float is exactly equal to the value you get
>> from the floating-point division 1/3.
>
>
> But the interpreter has no way of knowing that the value 1/3 that's been
> passed to the Fraction constructor was obtained from the division 1/3,
> rather than, say, 100000000000000001/300000000000000000 or
> 6004799503160661/18014398509481984. How do you propose the constructor
> should decide between the many possible fractions that round to the same
> float, if not by choosing the one that evaluates to it exactly?

It should choose the fraction with the least terms that rounds to the
float.  Whether "least" here means least numerator, least denominator,
least sum of the two, or whatever is not terribly important.

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


Thread

Unexpected results comparing float to Fraction Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-29 15:43 +0000
  Re: Unexpected results comparing float to Fraction Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-29 09:50 -0600
  Re: Unexpected results comparing float to Fraction MRAB <python@mrabarnett.plus.com> - 2013-07-29 17:09 +0100
  Re: Unexpected results comparing float to Fraction Chris Angelico <rosuav@gmail.com> - 2013-07-29 17:20 +0100
    Re: Unexpected results comparing float to Fraction Rotwang <sg552@hotmail.co.uk> - 2013-07-29 19:20 +0100
    Re: Unexpected results comparing float to Fraction Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-29 19:32 +0000
  Re: Unexpected results comparing float to Fraction MRAB <python@mrabarnett.plus.com> - 2013-07-29 17:48 +0100
    Re: Unexpected results comparing float to Fraction Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-29 17:27 +0000
  Re: Unexpected results comparing float to Fraction Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-29 10:40 -0600
    Re: Unexpected results comparing float to Fraction Rotwang <sg552@hotmail.co.uk> - 2013-07-29 19:16 +0100
      Re: Unexpected results comparing float to Fraction Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-29 13:33 -0600
  Re: Unexpected results comparing float to Fraction MRAB <python@mrabarnett.plus.com> - 2013-07-29 18:04 +0100
    Re: Unexpected results comparing float to Fraction Grant Edwards <invalid@invalid.invalid> - 2013-07-29 18:46 +0000
    Re: Unexpected results comparing float to Fraction Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-29 20:19 +0000
  Re: Unexpected results comparing float to Fraction Terry Reedy <tjreedy@udel.edu> - 2013-07-29 13:08 -0400
    Re: Unexpected results comparing float to Fraction Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-29 17:29 +0000
      Re: Unexpected results comparing float to Fraction Terry Reedy <tjreedy@udel.edu> - 2013-07-29 16:48 -0400
  Re: Unexpected results comparing float to Fraction Chris Angelico <rosuav@gmail.com> - 2013-07-29 18:14 +0100
  Re: Unexpected results comparing float to Fraction Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-29 11:35 -0600
  Re: Unexpected results comparing float to Fraction Serhiy Storchaka <storchaka@gmail.com> - 2013-07-29 22:34 +0300
  Re: Unexpected results comparing float to Fraction Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-29 14:35 -0600
  Unexpected results comparing float to Fraction Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-07-30 14:32 +0100
  Re: Unexpected results comparing float to Fraction Tony the Tiger <tony@tiger.invalid> - 2013-07-31 15:23 -0500
    Re: Unexpected results comparing float to Fraction Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-01 06:20 +0000
      Re: Unexpected results comparing float to Fraction Chris Angelico <rosuav@gmail.com> - 2013-08-01 07:32 +0100
      Re: Unexpected results comparing float to Fraction Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-08-01 10:44 +0100
      Re: Unexpected results comparing float to Fraction Chris Angelico <rosuav@gmail.com> - 2013-08-01 10:48 +0100

csiph-web