Find the answer to your Linux question:
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!...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User tech_man's Avatar
    Join Date
    Jan 2007
    Location
    USA
    Posts
    385

    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

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Something like (assuming you are using C/C++):

    Code:
    if( int(log(a)/log(b)) - log(a)/log(b) == 0 ) then {
    	// log(a)/log(b) equals an integer
    }
    Regards

  3. #3
    Linux User tech_man's Avatar
    Join Date
    Jan 2007
    Location
    USA
    Posts
    385
    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

  4. #4
    Linux User tech_man's Avatar
    Join Date
    Jan 2007
    Location
    USA
    Posts
    385
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •