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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:27:12+00:00 2026-06-06T08:27:12+00:00

From http://msdn.microsoft.com/en-us/library/system.math.pow.aspx int value = 2; for (int power = 0; power <= 32;

  • 0

From http://msdn.microsoft.com/en-us/library/system.math.pow.aspx

int value = 2;
for (int power = 0; power <= 32; power++)
    Console.WriteLine("{0}^{1} = {2:N0}",
                      value, power, (long) Math.Pow(value, power));

Math.Pow takes doubles as arguments, yet here we are passing in ints.

Question: Is there any danger of floating point rounding errors if there is an implicit conversion to double happening?

If yes, it is better to use something like:

public static int IntPow(int x, uint pow)
{
    int ret = 1;
    while (pow != 0)
    {
        if ((pow & 1) == 1)
            ret *= x;
        x *= x;
        pow >>= 1;
    }
    return ret;
}
  • 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-06T08:27:13+00:00Added an answer on June 6, 2026 at 8:27 am

    Yes, there is an implicit conversion to double happening, and yes there is a possibility of floating point rounding errors as a result.

    As to whether it’s worth using the alternate method you propose, that’s specific to the application. Is a floating point rounding error entirely unacceptable? Will you be using numbers that fit within int32 (it doesn’t take a whole lot for powers to overflow)?

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

Sidebar

Related Questions

I am using the example from: http://msdn.microsoft.com/en-us/library/system.io.driveinfo(v=vs.80).aspx To print drive information to a console
From the documentation here http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.layouttemplate.aspx i had customized the user interface of login control
So, this example comes right from MSDN. http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.readelementcontentasbase64.aspx Pretty much the only thing I
The following code was grabbed from MSDN: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx [MetadataType(typeof(ProductMetadata))] public partial class Product {
Using the function from: http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged.aspx public static byte[] encryptStringToBytes_AES(string plainText, byte[] Key, byte[] IV)
I see an example from the website http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser%28v=VS.90%29.aspx Here they are using a statement
From http://msdn.microsoft.com/en-us/library/system.io.memorystream%28v=VS.90%29.aspx : Memory streams created with an unsigned byte array provide a non-resizable
From http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute(VS.71).aspx: [C++] [StructLayout(LayoutKind::Explicit, Size=16, CharSet=CharSet::Ansi)] __value class MySystemTime { public: [FieldOffset(0)] short int
From this sample code from MSDN http://msdn.microsoft.com/en-us/library/system.string.gethashcode.aspx The hash code for abc is: 536991770
I got below code from http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx for adding custom property in webpart tool pane.

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.