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