Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point is broken in Python 2.0 #33624

Closed
anonymous mannequin opened this issue Dec 21, 2000 · 4 comments
Closed

Floating point is broken in Python 2.0 #33624

anonymous mannequin opened this issue Dec 21, 2000 · 4 comments

Comments

@anonymous
Copy link
Mannequin

anonymous mannequin commented Dec 21, 2000

BPO 226586
Nosy @tim-one

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2002-05-06.18:04:27.000>
created_at = <Date 2000-12-21.12:03:15.000>
labels = ['expert-IDLE', 'invalid']
title = 'Floating point is broken in Python 2.0'
updated_at = <Date 2002-05-06.18:04:27.000>
user = 'https://bugs.python.org/anonymous'

bugs.python.org fields:

activity = <Date 2002-05-06.18:04:27.000>
actor = 'tim.peters'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['IDLE']
creation = <Date 2000-12-21.12:03:15.000>
creator = 'anonymous'
dependencies = []
files = []
hgrepos = []
issue_num = 226586
keywords = []
message_count = 4.0
messages = ['2727', '2728', '2729', '2730']
nosy_count = 2.0
nosy_names = ['tim.peters', 'invader8']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue226586'
versions = []

@nobody
Copy link
Mannequin

nobody mannequin commented Dec 21, 2000

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>> p=0.6
>>> p
0.59999999999999998
>>>

@anonymous anonymous mannequin closed this as completed Dec 21, 2000
@anonymous anonymous mannequin closed this as completed Dec 21, 2000
@tim-one
Copy link
Member

tim-one commented Dec 21, 2000

This is not a bug.

Binary floating point cannot represent decimal fractions exactly,
so some rounding always occurs (even in Python 1.5.2).

What changed is that Python 2.0 shows more precision than before
in certain circumstances (repr() and the interactive prompt).

You can use str() or print to get the old, rounded output:

>>> print 0.1+0.1
0.2
>>>

Follow the link for a detailed example:

http://www.python.org/cgi-bin/moinmoin/RepresentationError

@invader8
Copy link
Mannequin

invader8 mannequin commented May 6, 2002

Logged In: YES
user_id=537045

This is still a problem in
Python 2.2 (#1, Dec 31 2001, 15:21:18)

It is a bug. Why would we expect that
the interactive prompt would behave
differently (worse) from using print?

@tim-one
Copy link
Member

tim-one commented May 6, 2002

Logged In: YES
user_id=31435

You may not like it, but it's not a bug. Read the docs for
a detailed explanation:

http://www.python.org/doc/current/tut/node14.html

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant