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 8745987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:07:28+00:00 2026-06-13T12:07:28+00:00

I am trying to optimize an audio-algoritm which has to calculate two algorithms like

  • 0

I am trying to optimize an audio-algoritm which has to calculate two algorithms like the following in every step. Now I’ve read, that there is no algorithm for logarithms that runs in polynomial time.
My question would be, if it would make sense to do all logarithms by a lookup table, since they are always the same, although the disadvantage of a large amount of memory access?

for(int f=1;f<11000;f++){
    for(int fk=1;fk<1000;fk++){
        int k = ceil(12 * log2f((f - 0.5) / fk));
    }
} 

I’m programming in C++.

Thanks alot!

  • 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-13T12:07:29+00:00Added an answer on June 13, 2026 at 12:07 pm

    If what you really need is

    ceil(12 * log2(/* something */))
    

    then there is a very simple O(1) computation which will work, using a table of only 12 values.

    1. Use frexp() to split the value into exponent and mantissa. (This is just bit manipulation, so it just takes a couple of cycles.)

    2. Look the mantissa up in a precomputed list of the powers of the 12th roots of 2.0 (divided by 2), which you can do with at most four comparisons.

    3. The result is 12*(exponent – 1) + index of the smallest root >= mantissa.

    Edited to add:

    There’s actually an even better solution, because the powers of the 12th root of two are reasonably evenly spread. If you divide [0.5, 1.0) (the range of the mantissa returned by frexp) into 17 evenly spaced subranges, each subrange will fall into one of two possible return values. So if you associate each subrange with an index into the vector of roots, you need only compare the target (within that range) with a single root.

    It’s too late for me to write coherent English, so you’ll have to settle for code:

    int Ceil12TimesLog2(double x) {
      int exp;
      double mantissa = std::frexp(x, &exp) * 2;
      int idx = indexes[int((mantissa - 1.0) * 17)];
      return 12 * (exp - 1) + (mantissa <= roots[idx] ? idx : idx + 1);
    }
    
    // Here are the reference tables.
    
    double roots[12] = {
      0x1.0000000000000p+0,
      0x1.0f38f92d97963p+0,
      0x1.1f59ac3c7d6c0p+0,
      0x1.306fe0a31b715p+0,
      0x1.428a2f98d728bp+0,
      0x1.55b8108f0ec5ep+0,
      0x1.6a09e667f3bccp+0,
      0x1.7f910d768cfb0p+0,
      0x1.965fea53d6e3dp+0,
      0x1.ae89f995ad3adp+0,
      0x1.c823e074ec129p+0,
      0x1.e3437e7101344p+0
    };
    int indexes[17] = { 0, 1, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11 };
    

    I tried this, and it brings the total computation time down from about 0.5 seconds (for log2f) to about 0.15 seconds, using the loop in the OP. The total size of the reference tables is 164 bytes.

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

Sidebar

Related Questions

I have been trying to optimize the two following nested loops: def startbars(query_name, commodity_name):
I'm trying to optimize the memory usage of an iOS app, and I'd like
I'm currently trying to optimize my program. I have a large database which consists
I'm trying to optimize the following C macro: rotate(v0, v1) a0 = v0, b0
I'm trying to optimize the following code below to avoid having to copy and
I am trying to optimize my search engine. Right now, I am running a
I'm currently trying to optimize my website, which is run on the Google App
I have been trying to optimize some code which handles raw pixel data. Currently
I am trying to optimize the speed of a query which uses a redundant
I'm trying to optimize the following query but I don't know what to do.

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.