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

maths float error #54773

Closed
ipcctv mannequin opened this issue Nov 28, 2010 · 2 comments
Closed

maths float error #54773

ipcctv mannequin opened this issue Nov 28, 2010 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@ipcctv
Copy link
Mannequin

ipcctv mannequin commented Nov 28, 2010

BPO 10564
Nosy @mdickinson
Files
  • tip.py: Code snippet of float problem
  • 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 2010-11-28.16:26:24.413>
    created_at = <Date 2010-11-28.15:50:33.511>
    labels = ['type-bug', 'invalid']
    title = 'maths float error'
    updated_at = <Date 2010-11-28.16:26:24.411>
    user = 'https://bugs.python.org/ipcctv'

    bugs.python.org fields:

    activity = <Date 2010-11-28.16:26:24.411>
    actor = 'mark.dickinson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-11-28.16:26:24.413>
    closer = 'mark.dickinson'
    components = []
    creation = <Date 2010-11-28.15:50:33.511>
    creator = 'ipcctv'
    dependencies = []
    files = ['19856']
    hgrepos = []
    issue_num = 10564
    keywords = []
    message_count = 2.0
    messages = ['122667', '122676']
    nosy_count = 2.0
    nosy_names = ['mark.dickinson', 'ipcctv']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10564'
    versions = ['Python 3.2']

    @ipcctv
    Copy link
    Mannequin Author

    ipcctv mannequin commented Nov 28, 2010

    Using IDLE 3.2a4
    Apologies in advance for probably wasting your time. If I'm wrong, just ignore me. I'm very new to Python. Is this a bug, my processor or me? I'm sending this in as I see it's an alpha release.

    If the user supplies 100 as the answer, I would have expected a result of 115 for a 15% tip. I get 114.999999999.

    @ipcctv ipcctv mannequin added the type-bug An unexpected behavior, bug, or error label Nov 28, 2010
    @mdickinson
    Copy link
    Member

    I get 114.999999999.

    How many '9's are there on what you're getting? If you really get '114.999999999' then something surprising is happening. If, on the other hand, you get '114.99999999999999', then it's all as expected. :-)

    The issue is one that affects the vast majority of popular programming languages, namely that numbers are stored internally in binary, so a number like 1.15 isn't exactly representable---you end up storing a (very good) approximation to 1.15 instead. And then when you multiply by 100, you end up with a (very good) approximation to 115.0.

    I highly recommend reading the floating-point section of the Python tutorial for an explanation of what's going on under the hood.

    http://docs.python.org/dev/py3k/tutorial/floatingpoint.html

    @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