Skip to content

Standardize modulo operator % on real numbers (step 1) #21745

@videlec

Description

@videlec

For any subset of the real numbers we change the modulo operator to be

x%y is the unique x' between [0,y) of the form x + ny with n integer

The main reason for the shift are the following incoherences

sage: 5 % 3
2
sage: 5. % 3.
-1.00000000000000

and

sage: 2/5 % 3
1
sage: 2./5. % 3.
0.400000000000000

The change mainly affects QQ and RR. This ticket concentrates on QQ. For other numbers see #21747.

The specifications for the transition period are as follows:

  • both // and % with rational arguments will return rationals
  • there will be a deprecation warning with (p/q) % (r/s) when p/q or r/s is not an exact integer
  • there will be a deprecation warning with (p/q) // (r/s) when the result is not an exact integer

See this sage-devel thread and also #15260

CC: @sagetrac-tmonteil

Component: basic arithmetic

Author: Vincent Delecroix

Branch/Commit: u/vdelecroix/21745 @ 39f4053

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

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