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

calculation bug in long() function #46393

Closed
must21 mannequin opened this issue Feb 18, 2008 · 3 comments
Closed

calculation bug in long() function #46393

must21 mannequin opened this issue Feb 18, 2008 · 3 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@must21
Copy link
Mannequin

must21 mannequin commented Feb 18, 2008

BPO 2140
Nosy @facundobatista

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 2008-02-18.12:25:04.698>
created_at = <Date 2008-02-18.12:18:06.057>
labels = ['type-bug', 'invalid']
title = 'calculation bug in long() function'
updated_at = <Date 2008-02-18.12:55:36.779>
user = 'https://bugs.python.org/must21'

bugs.python.org fields:

activity = <Date 2008-02-18.12:55:36.779>
actor = 'must21'
assignee = 'none'
closed = True
closed_date = <Date 2008-02-18.12:25:04.698>
closer = 'facundobatista'
components = ['None']
creation = <Date 2008-02-18.12:18:06.057>
creator = 'must21'
dependencies = []
files = []
hgrepos = []
issue_num = 2140
keywords = []
message_count = 3.0
messages = ['62523', '62524', '62526']
nosy_count = 2.0
nosy_names = ['facundobatista', 'must21']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue2140'
versions = ['Python 2.5', 'Python 2.4', 'Python 2.3', 'Python 2.2.3', 'Python 2.2.2', 'Python 2.2.1', 'Python 2.2', 'Python 2.1.2', 'Python 2.1.1']

@must21 must21 mannequin added the type-bug An unexpected behavior, bug, or error label Feb 18, 2008
@must21
Copy link
Mannequin Author

must21 mannequin commented Feb 18, 2008

betrag = 146.95
betrag = float(betrag)
betrag = betrag * 100.0
betrag = long(betrag)
print betrag

gives 14694 as result rather than 14695

@facundobatista
Copy link
Member

In short:

>>> long(100 * 146.95)
14694L

This is NOT a bug, but a behaviour of binary floating point:

>>> 146.95
146.94999999999999

In binary you can not express this number exactly.

>>> 146.95 * 100
14694.999999999998

When you long() that, you truncate the number, so it goes to 14694.

Please address further discussion through python-list.

Thanks!

@must21
Copy link
Mannequin Author

must21 mannequin commented Feb 18, 2008

thank you for fast reply

I see the point and do not want to argue about that (rounding is fine
for me). I just think this behaviour makes the long() function pretty
much useless.

Regards, Markus
Am 18.02.2008 um 13:25 schrieb Facundo Batista:

Facundo Batista added the comment:

In short:

>>> long(100 * 146.95)
14694L

This is NOT a bug, but a behaviour of binary floating point:

>>> 146.95
146.94999999999999

In binary you can not express this number exactly.

>>> 146.95 * 100
14694.999999999998

When you long() that, you truncate the number, so it goes to 14694.

Please address further discussion through python-list.

Thanks!

----------
nosy: +facundobatista
resolution: -> invalid
status: open -> closed


Tracker <report@bugs.python.org>
<http://bugs.python.org/issue2140\>


@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant