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

[with positive revew] automatic precision extension for long decimal literals does very strange things #962

Closed
sagetrac-cwitty mannequin opened this issue Oct 21, 2007 · 12 comments

Comments

@sagetrac-cwitty
Copy link
Mannequin

sagetrac-cwitty mannequin commented Oct 21, 2007

Long decimal literals become floating-point numbers whose precision depends on the length of the input literal in characters. See this script for some of the confusing (and, in my opinion, wrong) behavior that results.

sage: (1.10000000000000000000).prec()
73
sage: (1.10000000000000000000e0).prec()
79
sage: (1e-25).prec()
53
sage: (0.0000000000000000000000001).prec()
89
sage: (00000000.0000000000000000000000001).prec()
112

Component: basic arithmetic

Issue created by migration from https://trac.sagemath.org/ticket/962

@mwhansen
Copy link
Contributor

Attachment: 962.patch.gz

Initial version

@mwhansen
Copy link
Contributor

comment:4

I posted an initial patch which fixes some of the major issues. I would like others to comment on it to make sure the final version of this patch does the "right thing" since it will break lots of doctests.

@mwhansen
Copy link
Contributor

comment:5

Here is the behavior of the above examples after the patch:

sage: sage: (1.10000000000000000000).prec()
74
sage: sage: (1.10000000000000000000e0).prec()
74
sage: sage: (1e-25).prec()
87
sage: sage: (0.0000000000000000000000001).prec()
87
sage: sage: (00000000.0000000000000000000000001).prec()
87

@sagetrac-cwitty
Copy link
Mannequin Author

sagetrac-cwitty mannequin commented Nov 13, 2007

comment:6

Actually, I think that all of the last three examples should give 53 (that is, leading zeroes shouldn't affect the precision). I think that matches the rules for significant figures I learned in grade school...

@sagetrac-mabshoff sagetrac-mabshoff mannequin modified the milestones: sage-2.9.1, sage-2.8.13 Nov 16, 2007
@williamstein
Copy link
Contributor

comment:8

NOT YET -- note that I think many doctests will (and should) break after applying this patch, so this isn't being posted to actually include in the next release. It's being posted for feedback. After people like it, then Mike will post an additional patch that fixes all failing doctests.

I also think I agree with Carl witty's remark above about significant figures.

@sagetrac-cwitty sagetrac-cwitty mannequin changed the title automatic precision extension for long decimal literals does very strange things [with negative revew] automatic precision extension for long decimal literals does very strange things Nov 27, 2007
@sagetrac-cwitty sagetrac-cwitty mannequin changed the title [with negative revew] automatic precision extension for long decimal literals does very strange things [with partial patch (deliberately breaks doctests), with negative revew] automatic precision extension for long decimal literals does very strange things Nov 27, 2007
@mwhansen
Copy link
Contributor

mwhansen commented Dec 1, 2007

comment:11

Patch updated that now gives the following results:

sage: sage: sage: (1.10000000000000000000).prec()
74
sage: sage: sage: (1.10000000000000000000e0).prec()
74
sage: sage: sage: (1e-25).prec()
53
sage: sage: sage: (0.0000000000000000000000001).prec()
53
sage: sage: sage: (00000000.0000000000000000000000001).prec()
53

@sagetrac-cwitty
Copy link
Mannequin Author

sagetrac-cwitty mannequin commented Dec 1, 2007

comment:12

Attachment: 962-2.patch.gz

Looks good to me! Thank you for making so many changes at my request.

@sagetrac-cwitty sagetrac-cwitty mannequin changed the title [with partial patch (deliberately breaks doctests), with negative revew] automatic precision extension for long decimal literals does very strange things [with partial patch (deliberately breaks doctests), with positive revew] automatic precision extension for long decimal literals does very strange things Dec 1, 2007
@mwhansen
Copy link
Contributor

mwhansen commented Dec 2, 2007

comment:13

This causes the following doctest failures:

        sage -t  devel/sage-main/sage/modular/dirichlet.py
        sage -t  devel/sage-main/sage/gsl/dft.py
        sage -t  devel/sage-main/sage/functions/constants.py
        sage -t  devel/sage-main/sage/calculus/calculus.py
        sage -t  devel/sage-main/sage/calculus/wester.py
        sage -t  devel/sage-main/sage/interfaces/gp.py
        sage -t  devel/sage-main/sage/misc/functional.py
        sage -t  devel/sage-main/sage/rings/real_mpfr.pyx
        sage -t  devel/sage-main/sage/rings/fraction_field_element.py
        sage -t  devel/sage-main/sage/rings/rational.pyx
        sage -t  devel/sage-main/sage/rings/arith.py
        sage -t  devel/sage-main/sage/rings/integer.pyx
        sage -t  devel/sage-main/sage/rings/contfrac.py
        sage -t  devel/sage-main/sage/rings/qqbar.py
        sage -t  devel/sage-main/sage/rings/number_field/number_field.py
        sage -t  devel/sage-main/sage/rings/complex_number.pyx
        sage -t  devel/sage-main/sage/rings/complex_interval.pyx
        sage -t  devel/sage-main/sage/rings/polynomial/real_roots.pyx
        sage -t  devel/sage-main/sage/rings/polynomial/polynomial_element.pyx
        sage -t  devel/sage-main/sage/rings/polynomial/complex_roots.py
        sage -t  devel/sage-main/sage/rings/real_mpfi.pyx

I will post a patch in a bit fixing this.

@sagetrac-cwitty
Copy link
Mannequin Author

sagetrac-cwitty mannequin commented Dec 2, 2007

comment:14

Excellent! I read through 962-doctests.patch (yes, I really did), and I only saw one issue: on real_mpfr.pyx line 21, we will need to change:

    2147483647.00000         # 32-bit

to

    2.14748364700000e9       # 32-bit

@sagetrac-cwitty sagetrac-cwitty mannequin changed the title [with partial patch (deliberately breaks doctests), with positive revew] automatic precision extension for long decimal literals does very strange things [with positive revew] automatic precision extension for long decimal literals does very strange things Dec 2, 2007
@mwhansen
Copy link
Contributor

mwhansen commented Dec 2, 2007

comment:15

The patches should be applied in this order:

  1. 962-2.patch
  2. 962-doctests.patch

@mwhansen
Copy link
Contributor

mwhansen commented Dec 2, 2007

Attachment: 962-doctests.patch.gz

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Dec 2, 2007

comment:16

Merged in 2.8.15.alpha2.

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Dec 2, 2007
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