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
3 answers

How to compute (A^B)%M when A,B,M are big numbers?

For example, if A = 864927518, B = 1462579282 ,M = 193773611, how to compute (A^B)%M? Is there a simple way?
Ren
  • 2,852
  • 2
  • 23
  • 45
2
votes
2 answers

Raising a number to a fractional(Data.Ratio) power?

An expression like 2^(2%1) does not typecheck in GHCi, and the error messages are cryptic. Why does this not work, what do I need to change? I can't convert to another type, I want this for expressions like 27^(1%3).
Ludwik
  • 2,247
  • 2
  • 27
  • 45
2
votes
3 answers

Recursive Exponentiation

I'm trying to write a small program that calculate exponents recursively and I am a bit stuck. It is a homework assignment and we have been asked to have a base case, when the exponent is an odd number and when the exponent is even. So far I have…
Mikey
  • 149
  • 3
  • 13
2
votes
1 answer

C: Exponentiation over 256bit integers

I am dealing with an algorithm that operates on unsigned 256-bit integers, and I need to write a function that computes the value of the given formula uint256 compute(uint16 x) { return floor(exp2(x / 256)) - 1; } We can see that the equation…
Eipifi
  • 173
  • 9
2
votes
1 answer

Algorithm for tetration to work with floating point numbers

Tetration is the level above exponentiation (e.g: 2^^4 = 2^(2^(2^2)) = 65536. So far, I've figured out an algorithm for tetration that works. However, although the variable a can be floating or integer, unfortunately, the variable b must be an…
Dan W
  • 3,520
  • 7
  • 42
  • 69
2
votes
2 answers

Why is the inverse power of a int numpy array 0 despite "from __future__ import division"?

I always use from __future__ import division to avoid integer division problems. I just came across a case where it apparently still persists: np.array([10])**(-1) returns array([0]), contrary to 1/np.array([10]), which returns array([ 0.1]) as…
jacob
  • 869
  • 2
  • 10
  • 23
2
votes
3 answers

Tail-recursive pow() algorithm with memoization?

I'm looking for an algorithm to compute pow() that's tail-recursive and uses memoization to speed up repeated calculations. Performance isn't an issue; this is mostly an intellectual exercise - I spent a train ride coming up with all the different…
Dan
  • 1,314
  • 1
  • 9
  • 18
2
votes
2 answers

How do exponentiation algorithms work?

Exponentiation in most modern languages is easy .. I use the common operator for that in my language of choice or whatever function that compensates that to get the desired functionality. I want to know, how does this exactly work ? The following…
Amr Ayman
  • 1,129
  • 1
  • 8
  • 24
2
votes
2 answers

Calculating the powers of a vector elementwise

I have a vector [x, y, ...] in Octave and I would like to take the pth powers of the elements to get the new vector [x^p, y^p, ...]. Anybody has an idea how to do this?
2
votes
2 answers

overflow possibilities in modular exponentiation by squaring

I am looking to implement the fermat's little theorem for prime testing. Here's the code I have written: lld expo(lld n, lld p) //2^p mod n { if(p==0) return 1; lld exp=expo(n,p/2); if(p%2==0) return (exp*exp)%n; …
sudeepdino008
  • 3,194
  • 5
  • 39
  • 73
2
votes
2 answers

math function in javascript exponentiation

I have some calculation in javascript that includes exponentiation. Can any of you say why does this sentence return value 1??? alert ((0.03+1)^(271/365)-1); Thanks
Ilya Libin
  • 1,576
  • 2
  • 17
  • 39
2
votes
3 answers

Problem using map with a list of lists in Haskell

I am using Haskell to solve problem 99 in euler project, where I must find the maximum result from a list of base exponent pairs. I came up with this: prob99 = maximum $ map ((fst)^(snd)) numbers Where the numbers are in the form: numbers =…
Jonno_FTW
  • 8,601
  • 7
  • 58
  • 90
2
votes
5 answers

Return a large power (mod 2^32)

I need to work out a very large power modulo (2^32), i.e. I want the result of: y = (p^n) mod (2^32) p is a prime number n is a large integer Is there a trick to doing this efficiently in Java? Or am I stuck with doing it in a loop with n…
mikera
  • 105,238
  • 25
  • 256
  • 415
2
votes
1 answer

Modular Exponentiation

In C/C++ how can I calculate (a^b)%m where b does not fit into 64 bits? In other words, is there a way of calculating the above value using b%m instead of b? And is there any algorithm that can compute the above result in O(log(b)) time or…
sabari
  • 779
  • 2
  • 8
  • 14
1
vote
1 answer

BigDecimal.pow() of negative number

I just cannot find the correct answer, so here is my problem: I want to be able to calculate the indexation (a positive or negative percentage) over a price and period. Expectations: Case #1 Price : 1.000,00 Indexation percentage : 5% Calculation…
adis
  • 5,901
  • 7
  • 51
  • 71