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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:11:17+00:00 2026-05-30T09:11:17+00:00

I’m working on a Function that will do a POW long handed. It’s an

  • 0

I’m working on a Function that will do a POW long handed. It’s an assignment in dealing with function calls and variable hand offs rather than how to use math.h.

The function works to what the spec wants but I want to add (for my own ACD issues) a range filter.

I must use the prototype as given (double base, int exp).
I can’t add any headers…stuck with stdio.h and stdlib.h only.

I wanted to do log base(max_VALUE) > exp to check the exponent and base don’t exceed the maximum value that the double may hold. That worked.

What was happening though when I did testing of the power calcs using base 10 and any exponent over 22 was I’d get some erronious results. With 10^50 I would get a 1, 16 0s a 1 and the remainding 0s. If I did 10^23 I’d get 99999999999999992000000.00000.

I’m curious as to what’s going on at that magic 16 spot. What would be a good value to toss in there as a static value just to get the thing to work? Ideally I wanted to use size_of() and work out the max value but right now I don’t really care too much about that.

The filtering is all about my need to have code that doesn’t crash because of poor input validation.

Thanks in advance for your help!

Here’s what I have for the Function…

double Power( double base, int exp )
{


    int i;
    double max_VALUE = 1;
    double power_sum = 1;
    //  calculation of system specific max variable value - I would have used limits.h but thought
    //  the idea of lab was to have restraints on us so I did it long-handed.

    for ( i=0; i<(sizeof(base)*8); i++ )
        {
            max_VALUE *= 2;
        }

    //   'Out of Range' filter

            while (max_VALUE > base)
            {
                max_VALUE = max_VALUE / base;   // max_VALUE is divided by base until it becomes less
                i++;                            // than base. 'i' is the highest exponent this system can handle
            }                                   // for the given base. ( Slight fudge factor because I'm rounding it off. )
            if ( abs(exp) > i )
            {
                printf("\n\n*** Out of RANGE Error ***\n\n");
                return  0;
            }



    //  Power Calculation

    for(i=0;i < abs(exp) ;i++)       // Loop equals exponent value
    {
        power_sum *= base;
    }

    power_sum = ( exp < 0) ? ( 1 / power_sum ) : power_sum;  //corrects for negative exponent

    return power_sum;
}
  • 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-05-30T09:11:18+00:00Added an answer on May 30, 2026 at 9:11 am

    I’m curious as to what’s going on at that magic 16 spot.

    doubles have a 53-bit mantissa (usually, if IEEE754), that corresponds to roughly 16 decimal digits. So representing numbers as doubles gives you about 16 correct decimal digits, beyond that it may all be rounding error.

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post

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.