Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:26:46+00:00 2026-06-06T18:26:46+00:00

We are looking for the Nth root in PHP. We need to do this

  • 0

We are looking for the Nth root in PHP. We need to do this with a very large number, and the windows calculator returns 2. With the following code we are getting 1. Does anybody have an idea how this works?

echo bcpow(18446744073709551616, 1/64);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:26:47+00:00Added an answer on June 6, 2026 at 6:26 pm

    Well it seems that PHP and the BC lib has some limits, and after searching on the internet i found this interesting article/code:

    So you should use this function:

    <?php
    
    function NRoot($num, $n) { 
        if ($n<1) return 0; // we want positive exponents 
        if ($num<=0) return 0; // we want positive numbers 
        if ($num<2) return 1; // n-th root of 1 or 2 give 1 
    
        // g is our guess number 
        $g=2; 
    
        // while (g^n < num) g=g*2 
        while (bccomp(bcpow($g,$n),$num)==-1) { 
            $g=bcmul($g,"2"); 
        } 
        // if (g^n==num) num is a power of 2, we're lucky, end of job 
        if (bccomp(bcpow($g,$n),$num)==0) { 
            return $g; 
        } 
    
        // if we're here num wasn't a power of 2 :( 
        $og=$g; // og means original guess and here is our upper bound 
        $g=bcdiv($g,"2"); // g is set to be our lower bound 
        $step=bcdiv(bcsub($og,$g),"2"); // step is the half of upper bound - lower bound 
        $g=bcadd($g,$step); // we start at lower bound + step , basically in the middle of our interval 
    
        // while step!=1 
    
        while (bccomp($step,"1")==1) { 
            $guess=bcpow($g,$n); 
            $step=bcdiv($step,"2"); 
            $comp=bccomp($guess,$num); // compare our guess with real number 
            if ($comp==-1) { // if guess is lower we add the new step 
                $g=bcadd($g,$step); 
            } else if ($comp==1) { // if guess is higher we sub the new step 
                $g=bcsub($g,$step); 
            } else { // if guess is exactly the num we're done, we return the value 
                return $g; 
            } 
        } 
    
        // whatever happened, g is the closest guess we can make so return it 
        return $g; 
    }
    
    echo NRoot("18446744073709551616","64");
    
    ?>
    

    Hope this was helpful …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking in the jQuery core I found the following code convention: nth: function(elem, i,
Looking at some assembly code for x86_64 on my Mac, I see the following
I was looking at the Golden Ratio formula for finding the nth Fibonacci number,
Looking at the following code, does theme[sprite].img get nested inside result[definition].data (as theme[sprite].img is
I am looking for a way to optimise the following: $('ul li:nth-child(12n-5)').addClass('bk'); $('ul li:nth-child(12n-4)').addClass('bk95');
Can somebody help me out to troubleshoot this code? I am looking to add
Consider this F# code which computes a factor of a number: let n =
Looking to do a bit of refactoring... Using NHibernate I have this query currently
Looking at the Ehcahce implementation of net.sf.cache.JS107, I am trying to achieve the following
Looking for best advice on how to do this: I have an insert like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.