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


Groups > comp.lang.python > #38071

Re: Floating point calculation problem

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'string.': 0.04; 'python': 0.09; '3.0.': 0.09; 'integer,': 0.09; 'sat,': 0.15; 'value.': 0.15; 'eval': 0.16; 'evaluates': 0.16; 'expression.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.17; 'string,': 0.17; 'input': 0.18; '(or': 0.18; 'feb': 0.19; '2.x': 0.22; 'int,': 0.22; 'keyboard': 0.22; 'subject:problem': 0.22; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; 'post': 0.28; 'decimal': 0.29; 'point': 0.31; 'problem': 0.33; 'to:addr :python-list': 0.33; 'that,': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'along': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'your': 0.60; 'different': 0.63; 'skip:n 10': 0.63; 'obvious': 0.71; '2013': 0.84; 'demonstrates': 0.84; 'difference.': 0.84; 'etc,': 0.84; 'float,': 0.84
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:content-type; bh=QFXdf9IAm3TVdoYlbJx8hwOrmkKBGf40NFiMsN8HvZc=; b=0bjpxp4Lprx+I+M6YicFTOM0RRch2RLYIgwAdgwxwxXm3nCuv0r00B7W5gUn3GGbVi P/aW9rRWHb5lce4fSgjijQG4Uzk+Iaj/svQBmK1byzkHaLno8WlSK8tDaARLd/dj5M4q pvc6MHZkKrXxhNupmEZUrRl+0304Rf2vs2T7XRd5kg1/Uz+2CRvdJzIM7UusY+hEDC2G zHyKV+ee5Iu+S++UeeWAHljq7z9KDSDkoVYWwdyB4tWotFmsRH6ogm2Vs6P916Ua78mJ SCnv4W66xJEM3/+qTlHCJarIZ5guJ7sYQRUagrmcuR9tDZq9eODQyHsRrlphFmYBPBkI l09Q==
MIME-Version 1.0
X-Received by 10.49.84.104 with SMTP id x8mr19023176qey.5.1359805135640; Sat, 02 Feb 2013 03:38:55 -0800 (PST)
In-Reply-To <keitk2$hln$1@dont-email.me>
References <keipl5$kif$1@dont-email.me> <mailman.1289.1359801291.2939.python-list@python.org> <keisev$7v1$1@dont-email.me> <mailman.1291.1359804020.2939.python-list@python.org> <keitk2$hln$1@dont-email.me>
Date Sat, 2 Feb 2013 22:38:55 +1100
Subject Re: Floating point calculation problem
From Chris Angelico <rosuav@gmail.com>
To 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.1292.1359805138.2939.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359805138 news.xs4all.nl 6877 [2001:888:2000:d::a6]:56674
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38071

Show key headers only | View raw


On Sat, Feb 2, 2013 at 10:34 PM, Schizoid Man <schiz_man@21stcentury.com> wrote:
>> raw_input() takes a line from the keyboard (handwave) and returns it
>> as a string.
>>
>> input() in 2.X takes a line from the keyboard and evaluates it as a
>> Python expression.
>>
>> float() takes a string, float, int, etc, and returns the
>> nearest-equivalent floating point value.
>>
>> What's the input you're giving to it?
>
>
> Something simple like 3.0.

If your input has no decimal point in it, eval (or input) will return
an integer, not a float. Other than that, I can't see any obvious
reason for there to be a difference. Can you put together a simple
script that demonstrates the problem and post it, along with the exact
input that you're giving it, and the different outputs?

Chris Angelico

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


Thread

Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 10:27 +0000
  Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 21:34 +1100
    Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:14 +0000
      Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 22:20 +1100
        Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:34 +0000
          Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 22:38 +1100
            Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:51 +0000
              Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 22:58 +1100
                Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 15:48 +0000
                Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 15:54 +0000
                Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-03 03:00 +1100
                Re: Floating point calculation problem Michael Torrie <torriem@gmail.com> - 2013-02-02 11:19 -0700
                Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-03 12:25 +1100
                Re: Floating point calculation problem Dave Angel <d@davea.name> - 2013-02-02 21:20 -0500
                Re: Floating point calculation problem Michael Torrie <torriem@gmail.com> - 2013-02-02 21:22 -0700
              Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-02 23:11 +1100
      Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-02 22:45 +1100
        Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:50 +0000
  Re: Floating point calculation problem Chris Rebert <clp2@rebertia.com> - 2013-02-02 02:47 -0800
  Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-02 23:05 +1100

csiph-web