Opened 11 years ago

Closed 10 years ago

round incoherent with ceil/floor on rational numbers

Reported by: Owned by: zimmerma AlexGhitza minor sage-4.7 basic arithmetic round sage-4.7.alpha4 Simon Spicer Keshav Kini N/A

Description

Consider the following:

```sage: q=2^200/3^50
sage: q.floor()
2238393297946874000179418290327143433
sage: q.ceil()
2238393297946874000179418290327143434
sage: q.round()
2238393297946874000179418290327143433
```

This is fine so far. However:

```sage: floor(q)
2238393297946874000179418290327143433
sage: ceil(q)
2238393297946874000179418290327143434
sage: round(q)
2.23839329795e+36
```

We would expect `round(q)` to behave like `q.round()`.

Changed 10 years ago by spice

Changes the round() command to defer to an element's .round() method if no precision is specified.

comment:1 Changed 10 years ago by spice

• Authors set to Simon Spicer
• Keywords round added
• Status changed from new to needs_review

The above change alters the behaviour of sage's round() command. Before it *always* returned a real double field element; now it defers to an element's .round() method if no precision is specified, i.e. a sage Integer is returned in these cases. This makes round(x) and x.round() agree whenever x has a .round() method.

comment:2 Changed 10 years ago by kini

• Reviewers set to Keshav Kini
• Status changed from needs_review to positive_review

Five doctests failed, then failed to fail when I retested them, including devel/sage/sage/tests/startup.py . Code is easy to read and clearly does what it is intended to do, which intent I agree with. Everything looks good!

comment:3 Changed 10 years ago by jdemeyer

• Merged in set to sage-4.7.alpha4
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.