Questions tagged [exponentiation]

Anything related to the exponentiation operation, i.e. the process of computing the power of a number, and the corresponding syntax, semantics, constraints and implementation in programming languages.

Exponentiation is the process of raising a number to the nth power, (xn). Mathematically, it is denoted by superscripts, where the superscripted number is the exponent - xy.

However, since many text editors do not support superscripts, an alternative notation is used in code that uses exponentiation - typically a caret (x^y) or two asterisks (x**y). Other programming languages do not support symbolic operators for exponentiation, and rely on the pow function to calculate the exponent.

Please remember that the caret notation ^ may be used for bitwise XOR instead, and some languages does not support a built-in exponentiation operator.

See more

  • : a function that performs exponentiation. Namely, pow(a, b) calculates ab.
  • : do not assume that the ^ operator represents exponentiation. Many languages treat the ^ operator as bitwise-xor instead.
  • : The function ex, base-e exponentiation.
  • : Describes a type of curve produced by an exponent. Here, the the base is constant, and the variable is the exponent - and it grows extremely fast.
  • Wikipedia article for nore information about exponents and their identities.
368 questions
2
votes
1 answer

Is Groovy Power Operator (**) Broken in Associativity?

In Groovy 3.0 (Groovy Version: 3.0.0-rc-1 JVM: 11.0.2) println 3**3**3 println 3.0**3.0**3.0 gives 19683 19683 In Python (Python 3.5.2) from the terminal, I get >>> 3**3**3 7625597484987 >>> (3**3)**3 19683 The official site does not give any…
2
votes
2 answers

What's the most efficient algorithm to compute powers?

I'm simulating the RSA protocol for public and private key setup through Python 3 and I have to deal with huge exponents. Since the pow(base,exp) doesn't seem to run in a reasonable time I've been trying to use different algorithms, but for now none…
2
votes
2 answers

Exponentiation in Fortran/gfortran to high precision

How does gfortran handle exponentiation with a integer vs a real? I always assumed it was the same, but consider the example: program main implicit none integer, parameter :: dp = selected_real_kind(33,4931) real(kind=dp) :: x =…
user1887919
  • 829
  • 2
  • 9
  • 24
2
votes
1 answer

a factor that impacts RSA encryption/decryption time

"the RSA encryption or decryption time is roughly proportional to the number of bits in the exponent". I am assuming that it counts more on the position of the bits. For example, M^e. e1 = 10001 = 17 e2 = 00111 = 7 If M = 5, I think the calculation…
SecureFish
  • 2,391
  • 7
  • 32
  • 43
2
votes
1 answer

eslint rule forces exponentiation operator vs Math.pow causing ALL Jest test suites to fail with SyntaxError: Unexpected token *

I have an eslint rule rule cropping up in my code dissuading me from using Math.pow in favor of the ES6 alternative exponentiation operator. In react native I am trying to calculate the distance between touch gestures by calculating the x/y using…
Erik Grosskurth
  • 3,762
  • 5
  • 29
  • 44
2
votes
3 answers

Large exponents in C++

In C++, how can I calculate something like 2009^1389? (That's 2009 raised to the 1389th power, not the bitwise XOR.)
Alireza
  • 43
  • 2
  • 5
2
votes
1 answer

Unexpected output when using exponent operator(**) with float value in Python

I am currently using Python 3.6 in Windows 7. When I use exponent operator(**) with float that gives a large number, I get an unexpected output. For example, the output of "10^32" differs whether the exponent is in a form of an integer(32) or a…
2
votes
1 answer

Problems With Type Inference on (^)

So, I'm trying to write my own replacement for Prelude, and I have (^) implemented as such: {-# LANGUAGE RebindableSyntax #-} class Semigroup s where infixl 7 * (*) :: s -> s -> s class (Semigroup m) => Monoid m where one :: m class…
2
votes
2 answers

How to compute a^b^c mod p?

I am trying to compute a^b^c mod p for some positive integers a,b,c,p. One possible (and obvious) way is to use fast modular exponentiation which will run in O(log(b^c))=clog(b). While I don't mind the efficiency here, the obvious downfall of this…
AspiringMat
  • 2,161
  • 2
  • 21
  • 33
2
votes
2 answers

How to implement exponentiation of a rational number without nth root?

Its available for me only log(base "e"), sin, tan and sqrt (only square root) functions and the basic arithmetical operators (+ - * / mod). I have also the "e" constant. I'm experimenting several problems with Deluge (zoho.com) for these…
Alex
  • 3,325
  • 11
  • 52
  • 80
2
votes
2 answers

Power function in C gives the same output for large numbers

The problem statement requires me to find out the last digit of a^b. The constraints are that 0 <= a <= 20 and 0 <= b <= 2,147,483,000. My code works pretty well for numbers like 12^8 or 6^9 or something similar. But when I move to the large number…
Karan Singh
  • 1,114
  • 1
  • 13
  • 30
2
votes
4 answers

Big Integer Modular Exponentiation

How to calculate (xy) mod z with 1 <= x, y <= 101000 and z any positive integer 1 <= z < 231 ? What I have done so far is: scan x and y as a string, get the modulo, then calculate (xy) mod z. I know this is wrong because (xy) mod z is not equal to…
Ronald Sumbayak
  • 135
  • 2
  • 11
2
votes
2 answers

Numpy: Negative Execution Time for exponentiation operation

I am multiplying two large matrices, and it turns out the operation is faster when I first perform exponentiation on the first input: import time import numpy as np a = np.asarray(np.random.uniform(-1,1, (100,40000)), dtype=np.float32) b =…
MichaelSB
  • 3,131
  • 3
  • 26
  • 40
2
votes
1 answer

Turning a recursive procedure to a iterative procedure - SICP exercise 1.16

In the book Structure and interpretation of computer programs, there is a recursive procedure for computing exponents using successive squaring. (define (fast-expt b n) (cond ((= n 0) 1) ((even? n) (square (fast-expt b (/ n…
lightning_missile
  • 2,821
  • 5
  • 30
  • 58
2
votes
1 answer

Can't figure out printf function in assembly x86 and working with operands

I'm already nervous about posting this question, but here it goes. Im attempting to design an Assembly Program to take in two integers, then take in an operand (*, +, or ^). Then, depending on the operand, the program will perform the arithmetic…
Jamie Jackson
  • 86
  • 1
  • 12