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

String manipulation in matrices: a dimensional issue

I'm trying to define a function manipulating matrices of strings in R. {+,*} MATRICES MULTIPLICATION The {+,*}-product of two square matrices A and B of dimension n is a matrix C defined by the elements: Ci,j = Sumk=1,...,nAi,k * Bk,j. For example,…
gvdr
  • 63
  • 8
0
votes
2 answers

base 16 to base 2^64 conversion in GMP

I read in some hex numbers and I then would like to convert them to base 2^64. Unfortunately as this number cannot be stored in an int, it seems there is no function in GMP that can help me solve this problem. Is there another way to do this that I…
0
votes
1 answer

Modular exponentiation in C++

Something is wrong in my code for modular exponentiation and I can't spot the problem despite of writing it three times when using two different sources of pseudocode. I've read other questions about modular exponentiation in C++ on SE but that…
Qbik
  • 5,885
  • 14
  • 62
  • 93
0
votes
2 answers

Python: Recursion and return statements

I have this simple code using recursion that calculates the exponent. I understand how the recursion works here except for the: if exp <= 0: return 1. Say I call the function to give me five to the second power. If I have it return 1, it will give…
Tom Lilletveit
  • 1,872
  • 3
  • 31
  • 57
0
votes
1 answer

Exponentiation function intel assembly

Using bison to generate assembly code for a simple calculator, but I can't figure out exactly what my bug is here, all the answers seem to be one multiplication off... global intpow intpow: push ebp mov ebp,esp mov …
SetSlapShot
  • 1,298
  • 1
  • 21
  • 48
0
votes
2 answers

I want to generate the nth term of the sequence 1,3,8,22,60 ,164 in Order(1) or order of (nlogn)

This sequence satisfies a(n+2) = 2 a(n+1) + 2 a(n). and also a(n)=[(1+sqrt(3))^(n+2)-(1-sqrt(3))^(n+2)]/(4sqrt(3)). I am using C++ for me n can vary from 1 to 10^ 9. I need the answers modulo (10^9)+7 But speed here is very important My code with…
0
votes
1 answer

Assembly power returning wrong value

I'm trying to let the user enter 2 digits, the first one is the base and the second one the exponent. These two values are stored correctly. I know this by printing them (this printing code is currently commented out). However, my loop to calculate…
user1390504
  • 183
  • 4
  • 15
-1
votes
1 answer

Why JavaScript cannot properly calculate 9 ** 1/2? The output is 4.5 instead of 3

console.log(Math.pow(9, 1 / 2) === 9 ** 1 / 2) // false console.log(9 ** 1 / 2) // 4.5
Arzu
  • 1
  • 2
-1
votes
1 answer

To power of gives sometimes wrong answer

Whenever I run the program, input 2 for x 2 for y it will result 4 which is fine, but whenever I put in 2 to power of 3 it outputs 9 when it should output 8 and when I do 3 to power of 2 it outputs 8 when it should give 9. It works for 2^2, 2^4 but…
Dave
  • 1
  • 1
  • 9
  • 38
-1
votes
1 answer

Calculating a^b mod p for a large prime p

I'm trying to write a python code that calculates a^b mod p, where p = 10^9+7 for a list of pairs (a,b). The challenge is that the code has to finish the calculation and output the result in < 1 second. I've implemented successive squaring to…
Ibrahim M
  • 3
  • 1
-1
votes
2 answers

Write a function that for two numbers a and b returns their sum of squares a ^ 2 + b ^ 2 and (a + b) ^ 2 using pointers

My program return the wrong results. I honestly dont know where the problem is. a==5 and b==3, instead of returning the correct results, they return 2 for a ^ 2 + b ^ 2 and 10 for (a + b) ^ 2. Unless I am using pointers the wrong way, I do not know…
ile123
  • 57
  • 1
  • 6
-1
votes
1 answer

Could someone explain me how this matrix exponentiation function works?

#include using namespace std; //Program to find the nth fib number using matrix exponentation void multi_mat(int A[3][3], int B[3][3]) { int res_mat[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3;…
-1
votes
2 answers

A beginner question for Modulo with exponentiation calculation

The question is below but how is it calculated in Py and what command should I be entering in Py? Suppose you have $100, which you can invest with a 10% return each year. After one year, it's 100×1.1=110 dollars, and after two years it's…
Rahul John
  • 11
  • 2
-1
votes
5 answers

Simple Adding square of digits of a number

The result of this script is not the sum of the squares of the digits of a number, the first function works fine, I guess the problem is in the second function nToArray(a) { var res=[]; var s =a.toString(); for(i=0;i
Kepol
  • 149
  • 1
  • 8
-1
votes
1 answer

Working with exponentiation number in php

I have this number: 1.8112336829e+01 I get it from xml file with function simplexml_load $xml = simplexml_load_file("data.xml"); $number = $xml->data->row->v[1]; // assign number with the value 1.8112336829e+01 echo $number * 8; // outputs 1. I…
5less
  • 902
  • 1
  • 9
  • 18