vendredi 7 avril 2017

Optimised range checking and returning a value

I have below function which returns a value based on the input. I need to make this code as fast as possible, without using divison or modulo operator or loops. Each consecutive value is separated by amount almost equal to 6553.

int GetScalingFactor(int input)
{
    unsigned int factor = 0;

    if(input < 13107) factor = 72816;
    else if(input < 19660) factor = 81918;
    else if(input < 26214) factor = 93621;
    else if(input < 32767) factor = 109225;
    else if(input < 39321) factor = 131070;
    else if(input < 45874) factor = 163837;
    else if(input < 52428) factor = 218450;
    else if(input < 58981) factor = 327675;
}

Aucun commentaire:

Enregistrer un commentaire