Questions tagged [pow]

pow is a function that exists in various programming languages that usually takes two numbers as input and returns the first number to the power of the second number. DO NOT USE THIS TAG for questions relating to the Rack server, use [rack-pow] instead.

pow
100 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
7 votes
0 answers
1k views

AVX512 log2 or pow instructions

I need a AVX512 double pow(double, int n) function (I need it for a binomial distribution calculation which needs to be exact). In particular I would like this for Knights Landing which has AVX512ER. ...
Z boson's user avatar
  • 33.1k
6 votes
0 answers
3k views

pow() returning wrong result under specific conditions (and an unexpected fix) - Why is all this?

I have been creating a short program for implementing Sieve of Eratosthenes. In he program, I have used int startingPoint which held the value of the current prime number, which had it's ...
MrLumie's user avatar
  • 247
6 votes
3 answers
424 views

Three argument pow for arrays

pow accepts a third argument for modulo pow(x, y, z) that is more efficient computation than x ** y % z. How can you do that with arrays? What I've tried: >>> import numpy as np >>> ...
no step on snek's user avatar
3 votes
0 answers
387 views

Python - pow(-1, 0.5) returns non-zero real part

Python's builtin pow function pow(-1, 0.5) and exponentitaion function (-1)**0.5 return non-zero real value as 6.123233995736766e-17. Why is the real part of the complex number not absolute zero?
Preetkaran Singh's user avatar
3 votes
0 answers
453 views

Tensorflow 2 gradient gives nan results for pow

The following simplified code outputs nan for derivatives when x=0. I'm running tensorflow 2.0.0. import tensorflow as tf x = tf.Variable([[-1.0], [0.0], [1.0]]) with tf.GradientTape(persistent=...
wopkins's user avatar
  • 53
3 votes
1 answer
880 views

Using Pow in C++ MinGW. Works hard coded but not with variables

This is hopefully a simple linker issue but I've spent hours searching and haven't moved forward in that time. I'm trying to use #include <cmath> double aA = 2; double result = pow((double)...
Steve B's user avatar
  • 31
2 votes
0 answers
121 views

Is precision of pow in C dependent on scale of parameters?

Legacy code I am to maintain has a function with a variable x of type double. This variable contains a position measured in meters. It is expected to hold a value in the mm range, let's say 0.0001 <...
slingeraap's user avatar
2 votes
0 answers
5k views

RuntimeWarning: overflow encountered in power

I'm trying to do this calculation: import numpy as np res = (vol).dot(dose[:, np.newaxis]**(1/n))**n where: n = np.linspace(0.01, 0.50, 50) and vol is a numpy array with x-number of values ...
Denver Dang's user avatar
  • 2,573
2 votes
0 answers
234 views

Pow 0.5.0 install error on El Capitan

I've been trying to install Pow 0.5.0 on my fresh installation of El Capitan. I'm using their direct install script. I get the following error: ~ $ sudo curl get.pow.cx | sh % Total % Received % ...
Siddharth Arun's user avatar
2 votes
1 answer
2k views

how to exponentiate a number in Long format in Kotlin?

var count = 20L I need to raise the number to a power, but how to do it? this.pow() does not accept Long
chippa99's user avatar
1 vote
0 answers
40 views

How to use pow() in Objective-C?

I have this solution, in nineteen languages. I needs a pow() function (or operator) to calc from increase to interest rate and from interest rate to increase. The only language I can't calc it is in ...
Ricardo Erick Rebêlo's user avatar
1 vote
0 answers
120 views

Elixir / Pow Auth / ETS Cache - test raises error even if function works perfect

I created custom reset_password controller which works well during manual testing. Then I decided to write tests. Then problems started to appear. I read that I should mock cache and according to ...
Mateusz Babski's user avatar
1 vote
0 answers
106 views

How to derive power function for real number base and exponent in C

I am trying to implement fixed point C code for power function i.e. without using math.h library For example % base = linspace(-10,10,4) % exp = linspace(-5,5,4) I want to implement fixed point power()...
Coder's user avatar
  • 17
1 vote
2 answers
357 views

FAST get 10 to the power n(10^n) in C/C++

I want to calculate 10(yes only 10) to the power n[0..308] fast. i came up with some methods. 1) double f(int n) { return pow(10.0, n); } double f1(int n) { double a = 10.0; double res = 1.0; ...
DexterDong's user avatar
1 vote
1 answer
841 views

How to show numbers in cout without the "e" notation?

I tried to print a 'power table' of numbers without having them displayed using the "e" format but I can't figure out what's wrong. Here's my program: #include <iostream> #include <...
winter73's user avatar
1 vote
0 answers
38 views

Why is there a great difference in run times of pow() and ** while taking modulus in python?

import time start_time = time.time() c = (2**100000000) % 1000000007 end_time = time.time() print(end_time - start_time) start_time = time.time() c = pow(2, 100000000, 1000000007) end_time = time....
Siddharth Rai's user avatar
1 vote
0 answers
229 views

BigInteger exponentiation with negative number fails

I want to make numbers with negative exponents, how do I make them in Java? This is the formula I want to create in Java using BigInteger: ( k^-1 * (m + x*r) ) mod q. I made it like this: int expo = -...
adhiskara's user avatar
1 vote
2 answers
142 views

Python's pow() function and fast exponentiation gives different answers

I am getting different answers for below two implementations in C and python. In Python print(pow(15, 47413144071, 94826288143)) Prints 1 But in C #include<stdio.h> unsigned long Power(unsigned ...
Shashank's user avatar
1 vote
0 answers
318 views

RSA algorithm fails for some strings

Exercise 11.7 from Chapter 11 of Think Python, by Allen B. Downey, prompts the following: Exponentiation of large integers is the basis of common algorithms for public-key encryption. Read the ...
nsmedira's user avatar
1 vote
0 answers
177 views

Optimal size of std::map

I am using std::map key is 2 double pair and value as one double value. I am using it to cache power values. My question is at what size of map (cache) I can say like searching/insertion will take ...
Himanshu Saxena's user avatar
1 vote
1 answer
70 views

PHP wrong result with pow(11, 23)

I have a problem with pow(11, 23). The PHP result is 895430243255237361008640. According to this german encrypt tutorial (page 5) http://www.dkruse.de/dokumente/netzwerke/...
ABSimon's user avatar
  • 671
1 vote
1 answer
163 views

why can't I verify a `pow` function in a `while` loop?

I've been trying to solve this for an hour now and it is very frustrating, I cannot understand why the next loop just doesn't verify itself while(p>1) { p--; if (pow(n, contor) == p) { ...
jaketherazvy's user avatar
1 vote
0 answers
543 views

Computing powers in 64-bit assembly

I know that in 32-bit assembly, one can compute a power (the equivalent of pow(double, double) in C) using a combination of the x87 instructions FYL2X, F2XM1 and FSCALE. In 64-bit assembly, however, ...
DarkAtom's user avatar
  • 3,054
1 vote
0 answers
801 views

Math modified pow function for fractional exponents and negative bases

I've noticed that calculators and graphing programs like Desmos or Geogebra or Google (google search x^(1/3)) must have modified version the Math.pow() function that allows them to plot some negative ...
C9C's user avatar
  • 329
1 vote
2 answers
830 views

Power of elements in list

i have this example code: n = 11698030645065745910098695770921 e = 9569991810443215702618212520777 d = 7874909554574080825236064017913 m = 104228568138 m = int(m) e = int(e) n = int(n) def ...
Brian's user avatar
  • 13
1 vote
0 answers
275 views

how verifies the nonce produced by ethash through contract && add new opcode in EVM

I want to verify the pow of memory of one computer, then I use the ethash algorithm that used by ethereum to do the work. The problem is that the cache and dataset in the algorithm is too large for ...
Sanghai's user avatar
  • 47
1 vote
1 answer
407 views

Python 3 pow() / ** timing out

I'm undertaking a problem from Project Euler (#188) and I've run into a wall. The problem's specification is as follows: My solution in python is as follows: Q = input() List1 = [] List2 = [] ...
Jason_V's user avatar
  • 49
1 vote
2 answers
46 views

Someone know how to prove the result 'a^b % m = (...((a % m) * a) % m) ......* a) % m' from mathematical view?

Recently, I coded to realized RSA algorithm, I was confused by MOD-POWER problem, I couldn't why the equation is true, I can't give the proof of this equation: 'a^b % m = (...((a % m) * a) % m) ........
gann yee's user avatar
  • 141
1 vote
1 answer
82 views

pow() function in c produces truncation(or rounded) error?

Hi all:I am using pow() function in to calulate powers of primes.But some outputs don't show as expected. For example,when I feed 200 as input,I wish to print out all primes and their powers that do ...
vagrantlike's user avatar
1 vote
0 answers
61 views

Primality Testing in Java

So I'm doing some primality testing, using Fermat's test, and also a method I call Precise, which takes way too long for large integers, but is a solid reference point to wether my Fermat method is ...
jimkokko5's user avatar
1 vote
0 answers
72 views

Handling exponent when converting Excel formula to JS

I've got this Excel formula: (Assets*(1+Interest)^(CURRENT{age}+1‐Enrollment{age}))+(Salary*Employee{contribution}+Employer{contribution}))*((1+Interest)^(CURRENT{age}+1‐Enrollment{age})‐(1+Inflation)...
Keith Pickering's user avatar
1 vote
0 answers
124 views

exponent pow function returns wrong ASCII total

I am doing a function that turns a string into a number encoded as base 31. For example, "cat" => 'c' * 31^(3-1) + 'a' * 31^(3-2) + 't' = 67510 My code prints out as follows: Enter text to ...
narue1992's user avatar
  • 1,153
1 vote
0 answers
455 views

Pow server suddenly stopped working

As the title says, Pow just stopped working today. I simply get "Oops! Google Chrome could not connect to app.dev" when visiting the app.dev or IP address directly. curl: (7) couldn't connect to host ...
mike's user avatar
  • 1,546
1 vote
0 answers
2k views

Handling undefined, NaN or Inf Values in glsl. Thinking of matherrors

I still didn't get rid of some annoying bugs in my glsl shader (GL 2.0)... I searched for a solution of this problem for over 3 weeks now, but I didn't get any. There are many examples and ...
TheWhiteLlama's user avatar
1 vote
1 answer
116 views

Why am I getting unexpected output when using floor with pow?

So, I ran this code on my code blocks: #include<iostream> #include<cmath> using namespace std; int main() { int a; a=pow(10,9); cout<<a<<endl; a=ceil(pow(10,9))...
kik20's user avatar
  • 19
1 vote
3 answers
5k views

Calculating power function in logn time and constant space

This question I encountered while giving the interview. Lets say I wanted to calculate power(x, n) which is x^n. The best algorithm I know is calculating pow(x, n) in O(logn) time but that is a ...
rajgaut's user avatar
  • 19
0 votes
0 answers
108 views

What if we Initializing variable with 'double' instead of 'integer' while using pow() function as equation in c++?

I have been trying to solve a basic Armstrong problem in C++ using the pow() function. I'm encountering unexpected behavior while implementing a solution to compute Armstrong numbers in C++ using the ...
Adityan Verma's user avatar
0 votes
0 answers
119 views

Getting "ValueError: math domain error" in math.pow()

I'm getting ValueError: math domain error while running code like the one below (I simplified it): import math def f(x): return math.pow(x, -4) for i in range(10): print(f(i)) Also, I ...
Rumata_VII's user avatar
0 votes
1 answer
61 views

MSE giving negative results in High-Level Synthesis

I am trying to calculate the Mean Squared Error in Vitis HLS. I am using hls::pow(...,2) and divide by n, but all I receive is a negative value for example -0.004. This does not make sense to me. ...
Nah's user avatar
  • 21
0 votes
1 answer
75 views

power function is giving wrong output in C++

#include<iostream> #include<cmath> using namespace std; int binary_conversion(int e,int w,int q,int n,int i) { while(abs(w)>=1){//abs(e) to ensure that for negative numbers if(abs(...
Sarala .D's user avatar
0 votes
1 answer
92 views

What is the reverse of PHP function POW('base','exponent')?

I have gone through number of searches to find the solution to fine exponent or power of a value if we have base value and final value. Community helped each other a lot but didn't gave an answer ...
Shailender Ahuja's user avatar
0 votes
0 answers
103 views

How can used x^y instead of pow(x,y) in code in android studio?

For parametric programming, I need to use (for example : (x^3 + y^2)^(x + y) )instead of (pow(x,3) + pow (y,2) ,... in coding in Android Studio. Can anyone make a suggestion for this?
saeedbayat's user avatar
0 votes
1 answer
41 views

Discrepancy in Squaring a number stored in double format

I am trying to square a number x but there seems to be some discrepancy in precision while squaring it using Math.pow() and squaring it using multiplication. public class MyClass { public static ...
user91398's user avatar
0 votes
0 answers
62 views

incrrect result in pow and gcd function in c++

this is my code for RSA cryptosystem but I have an error with using the pow function that git an error solution c = pow(m,e)%n; and for gcd (greatest common divisor) I'm using #include numeric and ...
PRO man's user avatar
0 votes
1 answer
47 views

Representation of a pow function in the form of a loop

Hello I need help solving this task, if anyone had a similar problem it would help me a lot. I made a program that calculates the nth root of a number. Here's code: #include <stdio.h> #include &...
PC Safe's user avatar
  • 25
0 votes
0 answers
191 views

I have an issue calling pow function (c standard function ) from assembly

my code looks like so : extern pow global main section .text main : sub rsp , 8 movss xmm0 , [_1.2] movss xmm1 , [_2.3] call pow mov [result ] , rax add rsp , 8 ret section .data _1.2 : dq ...
Νίκος Αντωνετσής's user avatar
0 votes
1 answer
95 views

invalid operands to binary + c programming

Hi I'm finding a sum of polynomial in c, without massive, and i have this error that says " invalid operands to binary+(have 'float()(int, int, int)' and 'float()(int, int, int)'" here is ...
learner's user avatar
0 votes
0 answers
86 views

Errors on login with paypal with pow assent

I have trouble using the paypal api with my test app I am using pow_assent and using my own strategy... it sends me to the paypal page and everything works great until im redirected back to my site, ...
user15690889's user avatar
0 votes
0 answers
104 views

habit of pow(a, b) function in c++ (IDE Visual Studio 2019)

please, if somebody can explain. I have some questions about habit of pow(a, b) function in c++ (IDE Visual Studio 2019). During exercises I found strange habit of x++ and ++x in library function pow(...
Violeta Apkhazava's user avatar
0 votes
0 answers
152 views

pow() operator vs extended euclidan algorithm

I'm constructing a library that generates public keys and private keys for RSA encrypting. I got two big primes, p, q, that is 1024 bits. I want to compute the inverse of the public key e = 2**16 + 1 ...
Oskar's user avatar
  • 97