Skip to content

Implement modulus #402

Description

@Happypig375

AngouriMath.MathS.Modulus should be usable. Override (%) in AngouriMath Interactive too.

Activity

  1. added this to the Future milestone on May 13, 2021
  2. woods-20 commented on May 23, 2023

    @woods-20

    Just to add that this one would be really useful for me also.

  3. WhiteBlackGoose commented on May 23, 2023

    @WhiteBlackGoose
    Member

    I'm not going to work on AM any time soon, however, I'm always ready to review and merge PRs

  4. added a commit that references this issue on Aug 4, 2026
  5. Rafael-SOWNet commented on Aug 4, 2026

    @Rafael-SOWNet
    Member

    Implemented in #703, merged as 70fcbead.

    MathS.Mod(7, 3)                 // 1
    "(-7) mod 3".ToEntity().Evaled  // 2
    

    There is now a Modf node with the parser, MathS.Mod, the % operator on Entity, evaluation, simplification, differentiation, limits, both compilers, LaTeX and SymPy export.

    On the second half of your request — % in AngouriMath.Interactive — it needed no wrapper code at all. F# resolves % through op_Modulus, which is what the operator on Entity compiles to, so a % b in F# builds the kernel's node directly. There are F# tests covering it.

    Two notes on what it does, since both were decided deliberately:

    • The remainder is floored and takes the sign of the divisor, so (-7) mod 3 is 2 rather than -1. That is what a mathematician means by mod, and what SymPy, Mathematica and Maxima all answer; C's % truncates, but that is an operation on machine integers.
    • In a parsed string it is written mod, not %. % is left free to mean percent, which is what it means in mathematical writing. The % operator in C# and F# source is unaffected.
  6. modified the milestones: Future, 2.6.0 on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions