Opened 13 years ago

Closed 11 years ago

#2899 closed defect (fixed)

Make RDF round and friends return Integers

Reported by: jason Owned by: robertwb
Priority: major Milestone: sage-4.3.1
Component: coercion Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

> Also, round(RR(3.0)) returns an Integer...should RDF behave the same
> > way? (currently round(RDF(3.0)) returns an RDF).

We recently changed round, floor, ceiling, and trunc on RR to return
integers; yes, I think the corresponding RDF methods should change as
well.

Carl

Attachments (1)

2899-ncalexan-RIF-floor-ceil-1.patch (4.4 KB) - added by ncalexan 13 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 13 years ago by jason

The fix for #2898 will fix this.

Changed 13 years ago by ncalexan

comment:2 Changed 13 years ago by ncalexan

  • Summary changed from Make RDF round and friends return Integers to [with patch, needs review] Make RDF round and friends return Integers

This makes floor and ceil do what I expect for RIF. I believe that #2898 does make RDF work.

comment:3 Changed 12 years ago by craigcitro

  • Summary changed from [with patch, needs review] Make RDF round and friends return Integers to [with patch, needs rebase] Make RDF round and friends return Integers

I just tried to apply this against 3.2, and it fails. It's just a matter of moving the doctests around, I think.

comment:4 Changed 12 years ago by robertwb

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

This appears to have already been fixed.

----------------------------------------------------------------------
| Sage Version 3.4.2, Release Date: 2009-05-05                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------

sage: a = RDF(3.4)

sage: a.round(), a.floor(), a.ceil()
 (3, 3, 4)

comment:5 Changed 12 years ago by mabshoff

Did someone add a doctest? Otherwise this should not have been closed.

Cheers,

Michael

comment:6 Changed 12 years ago by mabshoff

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Reopening until someone either points to a doctests or post a doctest patch.

Cheers,

Michael

comment:7 Changed 12 years ago by ncalexan

  • Summary changed from [with patch, needs rebase] Make RDF round and friends return Integers to Make RDF round and friends return Integers

There are doctests for RDF for sure:

    def round(self):
        """
        Given real number x, rounds up if fractional part is greater than
        .5, rounds down if fractional part is less than .5.

        EXAMPLES::
        
            sage: RDF(0.49).round()
            0
            sage: a=RDF(0.51).round(); a
            1
        """
        return Integer(round(self._value))

    def floor(self):
        """
        Returns the floor of this number
        
        EXAMPLES::
        
            sage: RDF(2.99).floor()
            2
            sage: RDF(2.00).floor()
            2
            sage: RDF(-5/2).floor()
            -3
        """
        return Integer(math.floor(self._value))

    def ceil(self):
        """
        Returns the ceiling of this number
        
        OUTPUT: integer
        
        EXAMPLES::
        
            sage: RDF(2.99).ceil()
            3
            sage: RDF(2.00).ceil()
            2
            sage: RDF(-5/2).ceil()
            -2
        """
        return Integer(math.ceil(self._value))

comment:8 Changed 12 years ago by mabshoff

  • Milestone changed from sage-4.0.1 to sage-4.0
  • Resolution set to fixed
  • Status changed from reopened to closed

Excellent. Closed as fixed.

Cheers,

Michael

comment:9 Changed 12 years ago by mabshoff

  • Resolution fixed deleted
  • Status changed from closed to reopened

Wait. There are doctests via Nick's ticket, but that patch has not been merged into the Sage library, but fixed in some other way, i.e. the symbolics switch in 4.0. I assume.

In that case we might still need doctests, so until this is sorted out I am reopening this again :(

Cheers,

Michael

comment:10 Changed 12 years ago by was

  • Milestone changed from sage-4.0 to sage-4.0.1

comment:11 Changed 11 years ago by robertwb

  • Report Upstream set to N/A
  • Resolution set to fixed
  • Status changed from new to closed

There are doctests.

Note: See TracTickets for help on using tickets.