Opened 13 years ago

Closed 12 years ago

#4266 closed defect (fixed)

[with patch, positive review] overflow error in SR approx

Reported by: robertwb Owned by: burcin
Priority: major Milestone: sage-3.2.1
Component: calculus Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

sage: round(sqrt(Integer('1'*500)))
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
  File "/Users/robert/sage/current/local/lib/python2.5/site-packages/sage/misc/functional.py", line 865, in round
    except AttributeError: return RealDoubleElement(__builtin__.round(x, 0))
  File "/Users/robert/sage/current/local/lib/python2.5/site-packages/sage/calculus/calculus.py", line 6164, in __float__
    return float(f._approx_(float(g)))
  File "/Users/robert/sage/current/local/lib/python2.5/site-packages/sage/calculus/calculus.py", line 7941, in _approx_
    return math.sqrt(x)
OverflowError: math range error

Approx should fall back to mpfr if float fails.

Attachments (1)

4266-sr-round.patch (1.5 KB) - added by robertwb 13 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 13 years ago by mabshoff

  • Milestone set to sage-3.2

comment:2 Changed 13 years ago by robertwb

This is related to #188...

Changed 13 years ago by robertwb

comment:3 Changed 13 years ago by robertwb

  • Summary changed from overflow error in SR approx to [with patch, needs review] overflow error in SR approx

I assume there is good reason that "always return an RDF" is enforced. SR elements should probably implement round() themselves.

comment:4 Changed 12 years ago by mhansen

Actually, I don't know of a good reason that "always return as RDF" is enforced. It seems like floor, round, and ceiling should return Integers where possible. There is a trac ticket by Nick Alexander that does this for some objects.

comment:5 Changed 12 years ago by was

  • Summary changed from [with patch, needs review] overflow error in SR approx to [with patch, positive review] overflow error in SR approx

REFEREE REPORT:

The attached patch fixes the reported problem.

I agree that changing round, etc., to not return RDF's makes perfect sense, but I think that should be an entirely new trac ticket.

I doctested only the calculus tree after applying this patch, and all was good.

comment:6 Changed 12 years ago by mabshoff

  • Resolution set to fixed
  • Status changed from new to closed

Merged in Sage 3.2.1.rc0

Note: See TracTickets for help on using tickets.