Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Re: math

Re: math

From: Dave Wiard <lists_at_wiard.net>
Date: Wed, 06 Jul 2005 13:06:25 -0700

Ray Lambert wrote:
> BlueChip wrote:
>
>> while (x>0) r = (r<<3)+(r<<1); // r*8 + r*2
>> ^whoops
>>
>> 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);
>
> It might be a good idea to decrement x at some point too.... :)
>
>> while (x>0) r = (r<<3)+(r<<1); // r*8 + r*2
>
> perhaps:
>
> for (; x>0; --x) r = (r<<3)+(r<<1); // r*8 + r*2
>
> ~ray

And catch x=0. And set your base at 10 not 1 (remember, this is exp10).

if (x == 0) return 1; // 10^0 is always 1
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 = 10;
while (--x) r = (r << 3) + (r << 1); // r*8 + r*2
return r;

Dave
_______________________________________________
http://cool.haxx.se/mailman/listinfo/rockbox
Received on 2005-07-06

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy