Opened 2 years ago

Closed 2 years ago

#23502 closed defect (fixed)

.round() will not round an integer

Reported by: christelle Owned by:
Priority: minor Milestone: sage-8.1
Component: misc Keywords: round(), Integer, sd87
Cc: Merged in:
Authors: Kiran Kedlaya Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: b5f8abf (Commits) Commit: b5f8abf6b5cc02f0ce6247e6fe6a31768221e729
Dependencies: Stopgaps:

Description

The Sage function .round() cannot be called on an Integer. This can be annoying. For example,

sage: 7.round() 
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'round'

but

sage: 7.0.round() 
7

Change History (7)

comment:1 Changed 2 years ago by kedlaya

To make things even more confusing, the global round function does allow an integer input, but the output is not a Sage integer!

sage: u = round(7); u
7.0
sage: u.parent()
Real Double Field

According to the docstring for this function, "If no precision is specified this just calls the element's .round() method." This means that addressing the originally reported problem, by adding a .round() method to Sage integers which acts as the identity map, would fix this too.

comment:2 Changed 2 years ago by kedlaya

  • Branch set to u/kedlaya/_round___will_not_round_an_integer

comment:3 Changed 2 years ago by kedlaya

I have a branch to upload, but git trac push doesn't seem to be working for me right now. Will get this up as soon as I can.

comment:4 Changed 2 years ago by git

  • Commit set to b5f8abf6b5cc02f0ce6247e6fe6a31768221e729

Branch pushed to git repo; I updated commit sha1. New commits:

dd84106Add round method for integers
b5f8abfFix typo in doctest

comment:5 Changed 2 years ago by kedlaya

  • Authors set to Kiran Kedlaya
  • Status changed from new to needs_review

Waiting for patchbot, but in the meantime here goes.

comment:6 Changed 2 years ago by chapoton

  • Reviewers set to Frédéric Chapoton
  • Status changed from needs_review to positive_review

ok

comment:7 Changed 2 years ago by vbraun

  • Branch changed from u/kedlaya/_round___will_not_round_an_integer to b5f8abf6b5cc02f0ce6247e6fe6a31768221e729
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.