Skip to content

Methods __round__, __trunc__, __floor__, __ceil__ #25827

@fchapoton

Description

@fchapoton

https://docs.python.org/3/reference/datamodel.html?highlight=__round__#object.__round__

We should define these special methods so that the built-in round and math.trunc, math.floor, math.ceil can operate on Sage numbers.

This can help to eliminate imports of floor and ceil from sage.functions throughout the Sage library, which pulls in all of sage.symbolic.

Related: In the global namespace, we have:

  • round = sage.misc.functional.round,
  • floor = sage.functions.other.floor,
  • ceil = sage.functions.other.ceil,
  • trunc - undefined

CC: @jdemeyer @tscrim

Component: python3

Author: Frédéric Chapoton

Branch/Commit: public/ticket/25827 @ 53280c5

Issue created by migration from https://trac.sagemath.org/ticket/25827

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions