Timeline for Efficiently checking if a number is divisible by 3
Current License: CC BY-SA 3.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 17, 2014 at 16:31 | comment | added | supercat | @Marco13: Cool. The generated code sure looks a lot like my second suggestion above. | |
| Nov 17, 2014 at 9:15 | comment | added | Marco13 | @SteveJessop The JIT knows what to do. Coincidentally, I dissected this in stackoverflow.com/a/23451322/3182664 | |
| Jun 5, 2014 at 9:18 | comment | added | Steve Jessop |
The second code snippet is kind of like what gcc does with i % 3 in C++. I don't know how good JITs generally are with arithmetic, but I'd be somewhat disappointed if my JIT doesn't know this trick for constant divisors and use it where appropriate, so that I don't have to :-)
|
|
| Jun 3, 2014 at 18:21 | history | edited | 200_success | CC BY-SA 3.0 |
Fixed case sensitivity and "Possible loss of precision" compilation error
|
| Jun 3, 2014 at 18:06 | history | edited | supercat | CC BY-SA 3.0 |
added 314 characters in body
|
| Jun 3, 2014 at 4:44 | history | edited | supercat | CC BY-SA 3.0 |
Fixed code
|
| Jun 3, 2014 at 4:44 | comment | added | supercat | @ErikE: 0x5556. For integers 1-65535, (n*0x5555 >> 16) will compute (n-1)/3. Using 0x5556 avoids the -1 term. | |
| Jun 3, 2014 at 0:49 | comment | added | ErikE |
0x5555 or 0x5556?
|
|
| Jun 2, 2014 at 23:54 | history | answered | supercat | CC BY-SA 3.0 |