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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:41:52+00:00 2026-05-28T03:41:52+00:00

I was looking for an efficient approach for calculating a b (say a =

  • 0

I was looking for an efficient approach for calculating ab (say a = 2 and b = 50). To start things up, I decided to take a look at the implementation of Math.Pow() function. But in .NET Reflector, all I found was this:

[MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
public static extern double Pow(double x, double y);

What are some of the resources wherein I can see as what’s going on inside when I call Math.Pow() function?

  • 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-28T03:41:52+00:00Added an answer on May 28, 2026 at 3:41 am

    MethodImplOptions.InternalCall

    That means that the method is actually implemented in the CLR, written in C++. The just-in-time compiler consults a table with internally implemented methods and compiles the call to the C++ function directly.

    Having a look at the code requires the source code for the CLR. You can get that from the SSCLI20 distribution. It was written around the .NET 2.0 time frame, I’ve found the low-level implementations, like Math.Pow() to be still largely accurate for later versions of the CLR.

    The lookup table is located in clr/src/vm/ecall.cpp. The section that’s relevant to Math.Pow() looks like this:

    FCFuncStart(gMathFuncs)
        FCIntrinsic("Sin", COMDouble::Sin, CORINFO_INTRINSIC_Sin)
        FCIntrinsic("Cos", COMDouble::Cos, CORINFO_INTRINSIC_Cos)
        FCIntrinsic("Sqrt", COMDouble::Sqrt, CORINFO_INTRINSIC_Sqrt)
        FCIntrinsic("Round", COMDouble::Round, CORINFO_INTRINSIC_Round)
        FCIntrinsicSig("Abs", &gsig_SM_Flt_RetFlt, COMDouble::AbsFlt, CORINFO_INTRINSIC_Abs)
        FCIntrinsicSig("Abs", &gsig_SM_Dbl_RetDbl, COMDouble::AbsDbl, CORINFO_INTRINSIC_Abs)
        FCFuncElement("Exp", COMDouble::Exp)
        FCFuncElement("Pow", COMDouble::Pow)
        // etc..
    FCFuncEnd()
    

    Searching for "COMDouble" takes you to clr/src/classlibnative/float/comfloat.cpp. I’ll spare you the code, just have a look for yourself. It basically checks for corner cases, then calls the CRT’s version of pow().

    The only other implementation detail that’s interesting is the FCIntrinsic macro in the table. That’s a hint that the jitter may implement the function as an intrinsic. In other words, substitute the function call with a floating point machine code instruction. Which is not the case for Pow(), there is no FPU instruction for it. But certainly for the other simple operations. Notable is that this can make floating point math in C# substantially faster than the same code in C++, check this answer for the reason why.

    By the way, the source code for the CRT is also available if you have the full version of Visual Studio vc/crt/src directory. You’ll hit the wall on pow() though, Microsoft purchased that code from Intel. Doing a better job than the Intel engineers is unlikely. Although my high-school book’s identity was twice as fast when I tried it:

    public static double FasterPow(double x, double y) {
        return Math.Exp(y * Math.Log(x));
    }
    

    But not a true substitute because it accumulates error from 3 floating point operations and doesn’t deal with the weirdo domain problems that Pow() has. Like 0^0 and -Infinity raised to any power.

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

Sidebar

Related Questions

I'm looking for a fast and memory efficient approach for implementing Conway's Game of
RBAC is well understood, so this is beyond RBAC. Looking for an efficient/tested approach
I'm looking for an efficient approach to extracting a fragment of HTML from a
I am looking for a memory and performance efficient implementation of SortedSet<T> (corresponding to
ello, I am looking for the most efficient way to do the following: Take
I am looking for an efficient way to pull the data I want out
I'm looking for an efficient algorithm for scrambling a set of letters into a
I am looking for an efficient indexed persistent data structure. I typically work in
I am looking for an efficient eigensolver ( language not important, although I would
I'm looking for an efficient way to get the list of unique commit authors

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.