Opened 6 years ago

Closed 6 years ago

#15079 closed enhancement (fixed)

unique_round for RIF

Reported by: dkrenn Owned by:
Priority: major Milestone: sage-5.13
Component: basic arithmetic Keywords: rif, floor, ceil, round
Cc: Merged in: sage-5.13.beta5
Authors: Daniel Krenn Reviewers: Jeroen Demeyer
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by dkrenn)

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

Apply: trac_15079_unique_round.3.patch

Attachments (1)

trac_15079_unique_round.3.patch (2.6 KB) - added by dkrenn 6 years ago.

Download all attachments as: .zip

Change History (8)

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: 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: Changed 6 years ago by dkrenn

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

Replying to jdemeyer:

Why make a special case for self < 0?

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

This is bad:

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.

Corrected and tests added.

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

Replying to dkrenn:

Replying to 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)

Replying to jdemeyer:

Replying to dkrenn:

Replying to 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()?

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

Done now.

Changed 6 years ago by dkrenn

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.