Results 1 to 4 of 4
Is there a way to check and see if log(a)/log(5) equals a integer? Eg. log(125)/log(5) = 3 good! log(130)/log(5) = 3.024 bad!...
- 03-31-2007 #1
Double precision
Is there a way to check and see if log(a)/log(5) equals a integer? Eg. log(125)/log(5) = 3 good! log(130)/log(5) = 3.024 bad!
'Tis better to be silent and be thought a fool, than to speak and remove all doubt.'
--Abraham Lincoln
- 03-31-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Something like (assuming you are using C/C++):
RegardsCode:if( int(log(a)/log(b)) - log(a)/log(b) == 0 ) then { // log(a)/log(b) equals an integer }
- 03-31-2007 #3
I'm using C++, but:
if( int(log(125)/log(5)) - (log(125)/log(5)) == 0 )
cout << "Yes";
is still a no go. It will not print yes.'Tis better to be silent and be thought a fool, than to speak and remove all doubt.'
--Abraham Lincoln
- 03-31-2007 #4
Got it. I had to use a radius of equality.
bool almost_zero(double a)
{
float b = (a * 1000);
int c = int(b);
b = float(c) / 1000;
if(((int)a - b == 0))
return true;
else
return false;
}'Tis better to be silent and be thought a fool, than to speak and remove all doubt.'
--Abraham Lincoln


Reply With Quote