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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:51:48+00:00 2026-05-10T21:51:48+00:00

I’m wondering where I find the source to show how the operator ** is

  • 0

I’m wondering where I find the source to show how the operator ** is implemented in Python. Can someone point me in the right direction?

  • 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. 2026-05-10T21:51:49+00:00Added an answer on May 10, 2026 at 9:51 pm

    The python grammar definition (from which the parser is generated using pgen), look for ‘power’: Gramar/Gramar

    The python ast, look for ‘ast_for_power’: Python/ast.c

    The python eval loop, look for ‘BINARY_POWER’: Python/ceval.c

    Which calls PyNumber_Power (implemented in Objects/abstract.c):

    PyObject * PyNumber_Power(PyObject *v, PyObject *w, PyObject *z) {     return ternary_op(v, w, z, NB_SLOT(nb_power), '** or pow()'); } 

    Essentially, invoke the pow slot. For long objects (the only default integer type in 3.0) this is implemented in the long_pow function Objects/longobject.c, for int objects (in the 2.x branches) it is implemented in the int_pow function Object/intobject.c

    If you dig into long_pow, you can see that after vetting the arguments and doing a bit of set up, the heart of the exponentiation can be see here:

    if (Py_SIZE(b) <= FIVEARY_CUTOFF) {     /* Left-to-right binary exponentiation (HAC Algorithm 14.79) */     /* http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf    */     for (i = Py_SIZE(b) - 1; i >= 0; --i) {         digit bi = b->ob_digit[i];          for (j = 1 << (PyLong_SHIFT-1); j != 0; j >>= 1) {             MULT(z, z, z)             if (bi & j)                 MULT(z, a, z)         }     } } else {     /* Left-to-right 5-ary exponentiation (HAC Algorithm 14.82) */     Py_INCREF(z);   /* still holds 1L */     table[0] = z;     for (i = 1; i < 32; ++i)         MULT(table[i-1], a, table[i])      for (i = Py_SIZE(b) - 1; i >= 0; --i) {         const digit bi = b->ob_digit[i];          for (j = PyLong_SHIFT - 5; j >= 0; j -= 5) {             const int index = (bi >> j) & 0x1f;             for (k = 0; k < 5; ++k)                 MULT(z, z, z)             if (index)                 MULT(z, table[index], z)         }     } } 

    Which uses algorithms discussed in Chapter 14.6 of the Handbook of Applied Cryptography which describes efficient exponentiation algorithms for arbitrary precision arithmetic.

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

Sidebar

Related Questions

No related questions found

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.