Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38073
| From | "Schizoid Man" <schiz_man@21stcentury.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Floating point calculation problem |
| Date | 2013-02-02 11:50 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <keiugr$nq4$1@dont-email.me> (permalink) |
| References | <keipl5$kif$1@dont-email.me> <mailman.1289.1359801291.2939.python-list@python.org> <keisev$7v1$1@dont-email.me> <510cfc63$0$30002$c3e8da3$5496439d@news.astraweb.com> |
> Highly unlikely. I'd say impossible, unless you type a different value for > x > of course. By the time the input() function returns, the result is already > a float. Wrapping it in float() again cannot possibly change the value. If > you have found a value that does change, please tell us what it is. > > The only examples I can think of that will behave that way involve NANs > and > INFs. If you don't know what they are, don't worry about it, and forget I > mentioned them. For regular floating point values, I can't think of any > possible way that float(input(x)) and input(x) could give different > results. > No, the calculation returns in neither NaN or Inf at any point. > float(x) converts x into a float. > > - if x is already a float, it leaves it unchanged; > > - if x is a string, it converts it to the nearest possible float; > > - if x is some other numeric value (e.g. int, Decimal or Fraction, > but not complex) it converts it to the nearest possible float. > > > float(input()) is a waste of time. The dangerous part happens in the call > to > input(): a malicious user could type a Python command, and run arbitrary > code; or they could type something like "10**100**100" and lock up your > computer. Calling float *after* the call to input doesn't do anything. > > In Python 3.x, raw_input is gone, but float(input()) is safe -- it is > exactly equivalent to float(raw_input()) in Python 2.x. > > One other difference between Python 2.7 and 3.3 is that they sometimes > display floats slightly differently. Sometimes 3.3 will show more decimal > places: Thanks for that, I'll post the problematic code here shortly.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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