Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

16
LINES

< > BotCompany Repo | #1002512 - mod - better modulo that always gives positive numbers

JavaX fragment (include)

// better modulo that gives positive numbers always
static int mod(int n, int m) {
  ret (n % m + m) % m;
}

static long mod(long n, long m) {
  ret (n % m + m) % m;
}

static BigInt mod(BigInt n, int m) {
  ret n.mod(bigint(m));
}

static double mod(double n, double m) {
  ret (n % m + m) % m;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
1376 stefan See https://stackoverflow.com/questions/4412179/best-way-to-make-javas-modulus-behave-like-it-should-with-negative-numbers 2018-09-20 16:02:24

add comment

Snippet ID: #1002512
Snippet name: mod - better modulo that always gives positive numbers
Eternal ID of this version: #1002512/6
Text MD5: 1936192454dd7bea77ce7eb11b28000b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-09 11:31:06
Source code size: 314 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 671 / 698
Version history: 5 change(s)
Referenced in: [show references]