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 19 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, elmgxqgtpvxh, gjtlkbvenryc, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wnsclhtenguj

1 comment(s) hidden. show

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: 1078 / 5043
Version history: 5 change(s)
Referenced in: [show references]