Rockbox mail archive
Subject: Re: Math in Rockbox
while (x>0) r = (r<<3)+(r<<1); // r*8 + r*2
^whoops
At 19:52 06/07/2005, you wrote:
>what values of 'x' ? all positive? include 0?
>
>if (x<0) return(0); // cannot handle negative values of x
>if (x>9) return(1); // result will be > (2^32)1
>unsigned long r = 1;
>while (x>0) r = (r<<4)+(r<<1); // r*8 + r*2
>return (r);
>
>given you only have 9 possible return values, a lookup table would be
>faster and not THAT much more cost in codespace.
>
>At 16:53 06/07/2005, you wrote:
>>well... If I just think of a q&d solution:
>>
>>long exp10(int x) {
>> long result = 10;
>> while (x) {
>> result = result * 10;
>> }
>> return result;
>>}
>>
>>I haven't tested this, but it can be something like this. (And I'm sure
>>it's slow as hell for large values of x)
>>
>>Tomas
>>
>>lear@algonet.se wrote:
>>
>> >Hi,
>> >
>> >For an upcoming patch, I need some fixed or floatingpoint math. Does
>> anyone have
>> >a good fixedpoint implementation of pow(10, x) (or exp10(x)), or some
>> hints
>> >on how to implement it? It doesn't need to be particularly fast; small size
>> >is to be preferred actually.
>> >
>> >Or would it be acceptable to bring in the compiler's floating point
>> stuff for
>> >this? The idea is to not put it in a plugin or a codec (though I could put
>> >it in the codec lib, it isn't really the natural place for it :)...
>> >
>> > Magnus
>> >
>> >_______________________________________________
>> >http://cool.haxx.se/mailman/listinfo/rockbox
>> >
>> >
>>
>>_______________________________________________
>>http://cool.haxx.se/mailman/listinfo/rockbox
>
>_______________________________________________
>http://cool.haxx.se/mailman/listinfo/rockbox
_______________________________________________
http://cool.haxx.se/mailman/listinfo/rockbox
Received on Wed Jul 6 21:02:50 2005
Page was last modified "Jan 10 2012" The Rockbox Crew
