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
0
votes
2 answers

OverFlowError during exponentiation

I am having trouble calculating this. The code works for all values of N up to and including N = 57, but throws an overflow error (34, 'Result too large') for N greater than or equal to 58. Is there a way around this? Thanks. import numpy as…
DPdl
  • 723
  • 7
  • 23
0
votes
1 answer

SWI-Prolog evaluate -1 raised to a fraction, can this be done

In evaluating math expressions with SWI-Prolog I need to evaluate -1 raised to an exponential. When the exponential is an integer the result is as expected but when the exponential is a non-integer the result is undefined. Is it possible to evaluate…
Guy Coder
  • 24,501
  • 8
  • 71
  • 136
0
votes
1 answer

Not able to understand the approach taken in this fast exponentiation code?

I came across the following code snippet for fast exponentiation. I can see that it works correctly, but I do not understand the logic that the author used to code it up so concisely. I do know the fast exponentiation concept and the general code…
user3760100
  • 679
  • 1
  • 9
  • 20
0
votes
0 answers

Comparing chained exponents

Given two lists of small integers, is it possible to determine which list produces a larger result, when each element is raised to the power of the remaining elements? For example, the list 1,2,3 would be less than the list 5,4, since 1^2^3 <…
mako-taco
  • 722
  • 5
  • 10
0
votes
3 answers

Python: Syntax appears to be exponentiating an array? Help me interpret?

I'm trying to decipher some complicated code. Below, I've simplified the code, of what I do understand of it, to get to the heart of my question. scales = (2**arange(8, 12, .25)).astype(int) It seems to me that arange() creates an array of values,…
philosonista
  • 65
  • 2
  • 7
0
votes
2 answers

how does (int)exp.sample() work in the code?

ExponentialDistribution exp = new ExponentialDistribution(4.0); for(int i = 1; i < 20; i++){ timestamp[i] = (int)exp.sample() + 1+timestamp[i-1]; Here timestamp is an array of integers and a random value is assigned to it with…
0
votes
2 answers

What is the difference between division and exponentiation for a computer?

When trying to solve an optimization problem, I was constantly getting: RuntimeWarning: divide by zero encountered in divide Although analitically writing 1/x and x^(-1) are the same thing, re-writing my function by substituting each division as…
ma7642
  • 139
  • 2
  • 12
0
votes
1 answer

Modular Exponentiation with binary representation of exponent

Okay so I have an assignment to compute the binary representation of an integer and then reverse it into right to left notation and place that into a vector and perform modular exponentiation on it. I have the binary representation down, but I get…
kbman99
  • 21
  • 2
0
votes
1 answer

Fast floating point modpow

I am looking to compute a^b mod m where a & b are floating point numbers and m is an non-negative integer. The trivial solution is to do b multiplications which takes O(n) time, however my numbers a & b can be largish (~10 digits before the decimal…
will.fiset
  • 1,524
  • 1
  • 19
  • 29
0
votes
0 answers

Why python exponentiation with math.pow() yield overflow error and not with ** operator?

this question is different from [Exponentials in python x.**y vs math.pow(x, y) because a snippet using math.pow() cannot compute result, while the ** operator can. I am experimenting with a little snippet to compute first N doubly prime numbers…
user305883
  • 1,635
  • 2
  • 24
  • 48
0
votes
2 answers

Exponentiation not working

I'm new to programming, especially in Ruby so I've been making some basic projects. I have this code and as far as I know, it should work, but it gives results that I don't expect The program takes a and B and returns a^b. I did this as a…
0
votes
2 answers

why this code runs out of order

This is my code and I gave inputs to it as follows, I removed the step of giving a actual output value by the user, as it is calculated in the code, but still the same thing happens "1" for 1st input then "0.5" for 1st inputs weight then "0" then…
Kasun Siyambalapitiya
  • 3,956
  • 8
  • 38
  • 58
0
votes
2 answers

Exponentiation operator for Boolean in JavaScript?

Refer to this, the exponentiation operator returns the result of raising first operand to the power second operand, like the exponentiation operator in Python, which is part of the ECMAScript 2016 (ES7) proposal. We know the result of Boolean with…
zangw
  • 43,869
  • 19
  • 177
  • 214
0
votes
3 answers

Exponents without Math.pow() JavaScript

I need to write a program that takes two integers base and exponents and compute the exponents without using Math.Pow(). I have created the code using the Math.pow() method I can't figure out how to make it work without it. I have tried base^exp but…
user5500799
  • 63
  • 1
  • 3
  • 10
0
votes
3 answers

Calculate the sum of i^2453467 mod 2453468 for 1<=i<=999999 (^ means power)

How to do this type of problems efficiently in less time? I have tried to do this problem in Python but it's taking so much time. I have been thinking that maybe ^ mean xor not power but according to them it was power. This is a problem from a…
graypacket
  • 98
  • 1
  • 11