Opened 6 years ago

Closed 6 years ago

# unique_round for RIF

Reported by: Owned by: dkrenn major sage-5.13 basic arithmetic rif, floor, ceil, round sage-5.13.beta5 Daniel Krenn Jeroen Demeyer N/A

`RIF`-element has already `.unique_floor` and `.unique_ceil` and now has a `.unique_round`

Apply: trac_15079_unique_round.3.patch

### comment:1 Changed 6 years ago by dkrenn

• Authors set to Daniel Krenn
• Description modified (diff)
• Status changed from new to needs_review

### comment:2 follow-up: ↓ 3 Changed 6 years ago by jdemeyer

• Component changed from numerical to basic arithmetic
• Status changed from needs_review to needs_work

Why make a special case for `self < 0`? This is bad:

```sage: RIF(-1/2,-1/3).unique_round()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-6a343dbc6aff> in <module>()
----> 1 RIF(-Integer(1)/Integer(2),-Integer(1)/Integer(3)).unique_round()

/usr/local/src/sage-5.13.beta1/local/lib/python2.7/site-packages/sage/rings/real_mpfi.so in sage.rings.real_mpfi.RealIntervalFieldElement.unique_round (sage/rings/real_mpfi.c:15854)()

/usr/local/src/sage-5.13.beta1/local/lib/python2.7/site-packages/sage/rings/real_mpfi.so in sage.rings.real_mpfi.RealIntervalFieldElement.unique_round (sage/rings/real_mpfi.c:15959)()

ValueError: interval does not have a unique round (nearest integer)
sage: RIF(-1/2,1/3).unique_round()
0
```

If an interval doesn't have a unique round, a larger interval certainly should not have a unique round.

### comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 6 years ago by dkrenn

• Description modified (diff)
• Status changed from needs_work to needs_review

Why make a special case for `self < 0`?

Since `RIF(-1/2).unique_round()` should give `-1`.

```sage: RIF(-1/2,-1/3).unique_round()
...
ValueError: interval does not have a unique round (nearest integer)
sage: RIF(-1/2,1/3).unique_round()
0
```

If an interval doesn't have a unique round, a larger interval certainly should not have a unique round.

### comment:4 in reply to: ↑ 3 ; follow-up: ↓ 5 Changed 6 years ago by jdemeyer

Why make a special case for `self < 0`?

Since `RIF(-1/2).unique_round()` should give `-1`.

Sure, but then why don't implement `unique_round()` like `unique_floor()`?

### comment:5 in reply to: ↑ 4 Changed 6 years ago by dkrenn

• Description modified (diff)

Why make a special case for `self < 0`?

Since `RIF(-1/2).unique_round()` should give `-1`.

Sure, but then why don't implement `unique_round()` like `unique_floor()`?

Oh...how could I not see this...it is much simplier ;)

Done now.

### comment:6 Changed 6 years ago by jdemeyer

• Reviewers set to Jeroen Demeyer
• Status changed from needs_review to positive_review

### comment:7 Changed 6 years ago by jdemeyer

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