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

  • SEARCH
  • Home
  • 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 8570577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:35:25+00:00 2026-06-11T18:35:25+00:00

This is kind of obscure, but I need a function that can be computed

  • 0

This is kind of obscure, but I need a function that can be computed very quickly and resembles a^b where a is between 0 and 1 and b is very large. It will be calculated for one a at a time for many b’s. Ideally, the result would be within 0.4%. Thanks in advance.

  • 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-11T18:35:27+00:00Added an answer on June 11, 2026 at 6:35 pm

    Pulling my comments into an answer:

    Since you mention that b is large enough to be rounded to an integer, then one approach is to use the Binary Exponentiation algorithm by squaring.

    Math.pow() is slow because it needs to handle non-integral powers. So might be possible to do better in your case because you can utilize the integer powering algorithms.


    As always, benchmark your implementation to see if it actually is faster than Math.pow().


    Here’s an implementation that the OP found:

    public static double pow(double a, int b) {
        double result = 1;
        while(b > 0) {
            if (b % 2 != 0) {
                result *= a;
                b--;
            } 
            a *= a;
            b /= 2;
        }
    
        return result;
    
    }
    

    Here’s my quick-and-dirty (unoptimized) implementation:

    public static double intPow(double base,int pow){
        int c = Integer.numberOfLeadingZeros(pow);
    
        pow <<= c;
    
        double value = 1;
        for (; c < 32; c++){
            value *= value;
            if (pow < 0)
                value *= base;
            pow <<= 1;
        }
    
        return value;
    }
    

    This should work on all positive pow. But I haven’t benchmarked it against Math.pow().

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

Sidebar

Related Questions

I am sure that this kind of questions must have been asked before, but
Well this kind of n00b question but I still can't figure it out. I
Have data that has this kind of structure. Will be in ascending order by
This kind of code would normally work in PHP, but since the scope is
this kind of emergency, so please, can someone help me... I'm using movingboxes plugin
I've seen this kind of error box in Windows 7 (I can't remember exactly
How can I generate this kind of report for my project? http://maven.apache.org/plugins/maven-dependency-plugin/dependencies.html
Have data that has this kind of structure: $input = [ { animal: 'cat',
This question is kind of general and not very specific. We have a java
I want this kind of result from these tables. I even can't figure out

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.