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

Tkinter precision loss for doubles #38303

Closed
tim-one opened this issue Apr 14, 2003 · 5 comments
Closed

Tkinter precision loss for doubles #38303

tim-one opened this issue Apr 14, 2003 · 5 comments
Assignees

Comments

@tim-one
Copy link
Member

tim-one commented Apr 14, 2003

BPO 721171
Nosy @gvanrossum, @tim-one, @loewis
Files
  • _tkinter.fix: Stopgap fix using repr()
  • 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 = 'https://github.com/loewis'
    closed_at = <Date 2003-04-16.19:59:31.000>
    created_at = <Date 2003-04-14.15:32:08.000>
    labels = ['expert-tkinter']
    title = 'Tkinter precision loss for doubles'
    updated_at = <Date 2003-04-16.19:59:31.000>
    user = 'https://github.com/tim-one'

    bugs.python.org fields:

    activity = <Date 2003-04-16.19:59:31.000>
    actor = 'loewis'
    assignee = 'loewis'
    closed = True
    closed_date = None
    closer = None
    components = ['Tkinter']
    creation = <Date 2003-04-14.15:32:08.000>
    creator = 'tim.peters'
    dependencies = []
    files = ['841']
    hgrepos = []
    issue_num = 721171
    keywords = []
    message_count = 5.0
    messages = ['15461', '15462', '15463', '15464', '15465']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'tim.peters', 'loewis']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue721171'
    versions = []

    @tim-one
    Copy link
    Member Author

    tim-one commented Apr 14, 2003

    DoubleVar.set() (I think) goes thru PyObject_Str(),
    causing precision loss for doubles:

    >>> import Tkinter
    >>> import math
    >>> x = Tkinter.DoubleVar(Tkinter.Tk())
    >>> x.set(math.pi)
    >>> x.get()
    3.1415926535900001   # not good
    >>> math.pi
    3.1415926535897931   # original precision
    >>> eval(str(math.pi))
    3.1415926535900001   # reproduces Tk result
    >>>

    Reported on c.l.py. Guido says you may know how to
    create a "native" Tcl/Tk double in this case instead.

    @gvanrossum
    Copy link
    Member

    Logged In: YES
    user_id=6380

    If a proper fix using Tcl float/double objects doesn't work
    for some reason, maybe the attached fix (_tkinter.fix) would
    work?

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Apr 15, 2003

    Logged In: YES
    user_id=21627

    I have now fixed this for _tkinter.c 1.154, by passing all
    .set arguments with the same object type to Tcl, and
    retrieving all Tcl variables with their native type.

    This causes slight semantic changes (like the one being
    reported as a bug here); most notably:

    >>> y=Tkinter.StringVar(Tkinter.Tk())
    >>> y.set(3.14)
    >>> y.get()
    3.1400000000000001

    So a StringVar may not return a string anymore if .set did
    not enter a string. Does that need to get fixed?

    @gvanrossum
    Copy link
    Member

    Logged In: YES
    user_id=6380

    Thanks!

    Re StringVar: I think StringVar should coerce the result to
    str(), just like IntVar coerces to int(), etc. Maybe
    Variable should grow get() method that does no coercion, and
    it should no longer be marked as an internal class.

    BTW there are a few places in Tkinter docstrings that
    promise 0 or 1 where a bool is now returned.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Apr 16, 2003

    Logged In: YES
    user_id=21627

    In Tkinter.py 1.172, StringVars now always returns strings
    (potentially Unicode); doc strings have been changed to
    mention bools.

    @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

    2 participants