Click here to Skip to main content
15,885,757 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 5:45
BobJanova5-Jul-11 5:45 
GeneralRe: Modulo statement Pin
David19875-Jul-11 6:03
David19875-Jul-11 6:03 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 7:13
BobJanova5-Jul-11 7:13 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 3:13
BobJanova5-Jul-11 3:13 
GeneralRe: Modulo statement Pin
David19875-Jul-11 3:14
David19875-Jul-11 3:14 
GeneralRe: Modulo statement Pin
Lutosław5-Jul-11 5:13
Lutosław5-Jul-11 5:13 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 5:43
BobJanova5-Jul-11 5:43 
GeneralRe: Modulo statement Pin
David19875-Jul-11 6:19
David19875-Jul-11 6:19 
I started doing crazy things such as:
C#
static int SpecialModulo(int x)
{
    return (x & 7) - ((x & 8) >> 1) - ((x >> 31) & 4);
}

Trying to make a branchless version..

And then I realized.. why not just use a lookup table?
C#
int[] table = new int[] { 0, 1, 2, 3, 4, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, -4, -3, -2, -1 };

x = table[x + 12]; // that's all

GeneralRe: Modulo statement Pin
Lutosław5-Jul-11 6:46
Lutosław5-Jul-11 6:46 
GeneralRe: Modulo statement Pin
David19875-Jul-11 6:53
David19875-Jul-11 6:53 
GeneralRe: Modulo statement Pin
Lutosław5-Jul-11 7:24
Lutosław5-Jul-11 7:24 
GeneralRe: Modulo statement Pin
David19875-Jul-11 7:40
David19875-Jul-11 7:40 
GeneralRe: Modulo statement Pin
Lutosław5-Jul-11 10:47
Lutosław5-Jul-11 10:47 
QuestionC# Hash Sum - Add Bytes Pin
John Paul Walker4-Jul-11 17:03
John Paul Walker4-Jul-11 17:03 
AnswerRe: C# Hash Sum - Add Bytes Pin
Roger Wright4-Jul-11 17:38
professionalRoger Wright4-Jul-11 17:38 
GeneralRe: C# Hash Sum - Add Bytes Pin
John Paul Walker5-Jul-11 12:24
John Paul Walker5-Jul-11 12:24 
GeneralRe: C# Hash Sum - Add Bytes Pin
Matty2225-Sep-11 21:08
Matty2225-Sep-11 21:08 
AnswerRe: C# Hash Sum - Add Bytes Pin
BobJanova5-Jul-11 1:14
BobJanova5-Jul-11 1:14 
GeneralRe: C# Hash Sum - Add Bytes Pin
David19875-Jul-11 2:01
David19875-Jul-11 2:01 
Questionfind all 'n'-bit numbers with 'k' bit set [modified] Pin
Sameerkumar Namdeo1-Jul-11 23:46
Sameerkumar Namdeo1-Jul-11 23:46 
AnswerRe: find all 'n'-bit numbers with 'k' bit set Pin
David19872-Jul-11 0:15
David19872-Jul-11 0:15 
GeneralRe: find all 'n'-bit numbers with 'k' bit set Pin
Sameerkumar Namdeo2-Jul-11 1:01
Sameerkumar Namdeo2-Jul-11 1:01 
QuestionSewer Colony Optimization Algorithm Pin
Anubhava Dimri30-Jun-11 18:05
Anubhava Dimri30-Jun-11 18:05 
AnswerRe: Sewer Colony Optimization Algorithm Pin
Roger Wright30-Jun-11 19:05
professionalRoger Wright30-Jun-11 19:05 
QuestionKnapsack Problem Algorithm [modified] Pin
Nikolay Nedelchev29-Jun-11 8:24
Nikolay Nedelchev29-Jun-11 8:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.