openlang

Nim remainder syntax

How is modulus expressed in Nim?

cell % 7 == 0 gives undeclared identifier: '%'

Neither a Google search nor looking through SO turned up the answer.

The conversation continues 2

Follow the reasoning
  1. Permalink

    Some answers recommend %%, but you shouldn't use that. It dates back to when signed integers were the only integers Nim provided. Operators whose names finish in %, such as <%, treat those signed integer values as unsigned ints. Nim has supported unsigned integers for some time, so just choose mod, whose overloads correctly cover the applicable integral types: https://nim-lang.org/docs/system.html#mod,int,int

Other sides of the same question

  1. Choosing enum entries randomly with GDScript in Godot 3.3 without listing each one?

    Here's the enum declaration I'm using in GDScript: I'd like to choose an enum variant randomly without listing every possible…

    Replies 2Latest activity gdscript
  2. Returning results from an APL function

    How do I make my function return something once execution has finished? For instance, I have: ROUTINE N ? N ⍴ 12 //That gener…

    Replies 2Latest activity apl
  3. Declaring an array containing constant strings

    Is it possible for Delphi to declare a string array using something like the example below?

    Replies 4Latest activity object-pascal