[solved] Need a way to calculate these multipliers

Hello :slight_smile:

So I won’t explain why I need to do that but suppose I have a function like this

float calculateSomething( int input )
    return input * <multiplier calculation here>

I need this function to output values like so:

For an input value 128, it would be multiplied by 16
For an input value 256, it would be multiplied by 4
For an input value 512, it would be multiplied by 1
For an input value 1024, it would be multiplied by 0.25

etc but not only for powers of 2 as input, but for any numbers . I can’t find how I can calculate these values. Maybe something about shifting bits, but I don’t see a pattern :frowning:

I think it’s simple but I just don’t find it… Any idea? Thanks in advance :slight_smile:

Your question makes no sense. If you want to evaluate a formula, then you need the formula. Or are you looking for some kind of interpolation ?

262144.0 / input

This code will generate output which matches your examples

float log2 = log(2);
float a = log(input)/log2 ;
float b = 18.0-(2.0*a);
float m = exp( b*log2 ) ;
float ans = m*input ;
return ans ;

graph out your numbers, you'll see a formula there.
It's probably some exponential curve.

Thanks all, but christop's worked... I'm very embarrassed :blush: Let's say that I need to sleep more.. :slight_smile:

Hey ! Mine works too. But I think christops is better.