https://bitbucket.org/daniel_fort/magic-lantern
Raw File
Tip revision: e3905159d1050578108c2c1947d8e6bcabfcfe02 authored by alex@thinkpad on 21 June 2018, 06:08:58 UTC
Close branch crop_rec_4k_mlv_snd_audio_issue
Tip revision: e390515
imath.c
/* integer math */

#include "dryos.h"
#include "math.h"

int powi(int base, int power)
{
    int result = 1;
    while (power)
    {
        if (power & 1)
            result *= base;
        power >>= 1;
        base *= base;
    }
    return result;
}

int log2i(int x)
{
    int result = 0;
    while (x >>= 1) result++;
    return result;
}

int log10i(int x)
{
    int result = 0;
    while(x /= 10) result++;
    return result;
}

/* todo: integer-only implementation? */
uint32_t log_length(int v)
{
    if (!v) return 0;
    return (unsigned int)(log2f(v) * 100);
}
back to top