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.

Filter by
Sorted by
Tagged with
-2 votes
0 answers
61 views

Using pow for openMP for GPU

I am trying to run an OMP for loop on GPU that is using pow to calculate the power of a value and when running openMP for GPU it doesn't recognise the pow function #pragma omp target teams distribute ...
Andrew Chedid's user avatar
0 votes
1 answer
90 views

Python pow function not returning correct values for large numbers?

I'm trying to use values generated by an RSA algorithm in python by using python's pow function with 3 arguments but it doesn't seem to be returning correct values for large numbers. For example if I ...
Quibbs's user avatar
  • 13
1 vote
1 answer
11 views

Exponentiation with Negative Bases in DolphinDB

As shown in the following script, I want to raise all elements of x to the power of y. x=[-3,-2,3,3,3,4] y=[1/3.0,0.334,0.334,1/3,1/3.0,2] pow(x,y) I noticed that the result contains NULL values for ...
JaneYe's user avatar
  • 181
-1 votes
1 answer
88 views

Why pow(x, y, z) not equal to pow(x, y) % z when y is -1 in Python 3.9.6?

Here is my exmaple: pow(100, -1 , 321) # output 61 pow(100, -1) % 321 # output 0.01 100 ** -1 % 321 # output 0.01 I know that pow(x, y, z) should be equal to pow(x, y) % z or x ** y % z, but in my ...
L-ING's user avatar
  • 13
0 votes
1 answer
63 views

Java Pow Of 2 Gives me a Wrong answer

class Solution { int mod = (int) (1e9) + 7; int modPow(long base, long exponent) { if (exponent == 0) return 1; long result = 1; while (exponent > 0) { ...
Hemanthkumar Pujari's user avatar
0 votes
0 answers
81 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
-1 votes
2 answers
95 views

Power function [pow()] always giving a ZERO as result [closed]

Power function always giving a zero(0) as result no matter the input. I am learning the power function, but it doesn't work.please help. #include <stdio.h> #include <math.h> int main() {  ...
N-CODER's user avatar
0 votes
1 answer
57 views

Why this python code throw OverflowError?

Today, I was doing the leetcode 50 MyPow , and I decided to use the recursion to achieve it. My code is as follows: class Solution: def myPow(self, x: float, n: int) -> float: if n >...
Francis Hui's user avatar
2 votes
2 answers
115 views

Using power function in C

I am writing a program in which I have to check whether the number entered by the user is armstrong or not to do the calculation I am using the power function but there seems to be an error. I tried ...
Vishwas Rana's user avatar
0 votes
1 answer
80 views

Power function in SPARQL

Does anybody know if there is any power function added for SPARQL? My quick-fix is using BIND and string process but it's not optimal at all: ?contract part:price ?price_E ; part:Currency ?...
Ckk's user avatar
  • 3
0 votes
0 answers
23 views

Getting extra digit while multiplying a value in C# [duplicate]

Can anyone please share why I am getting extra 000000005 while doing below operation double value = 42923496; double res = value * Math.Pow(10, -4); //4292.3496000000005 Expected 4292.3496 Expected ...
Agina's user avatar
  • 11
2 votes
1 answer
225 views

What are the differences between a**b and pow(a,b), in symbolic calculation

EDIT: added assert as suggested by Wrzlprmft, which does not raise any exception. I have to write code with many expressions of type a**b, under the following circumstances import sympy as sp a, b = ...
sancho.s ReinstateMonicaCellio's user avatar
0 votes
1 answer
41 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
73 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
-1 votes
1 answer
151 views

How to reverse find "b" in pow(a, b, c)?

from Crypto.Util.number import * from Crypto.Util.Padding import * # TEXT is unkown a = 2 b = bytes_to_long(pad(TEXT, 256)) c = getStrongPrime(1024) #...
hexa's user avatar
  • 24
1 vote
1 answer
154 views

pow large numbers in Python

How can I raise large numbers to a power in python? a = 62608558862573792084872798679396455703616395237802859621162736207631538899993 b = ...
jaroslaw's user avatar
0 votes
1 answer
73 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
1 answer
24 views

Fast way to generate a vector of successive powers in DolphinDB

Suppose the base value is x, I would like to create a vector [1, x, x** 2, x** 3,.... , x**n-1] where the i-th element is Xi. I know in Python it can be implemented with a list. For x=5 and n=10: [pow(...
FFF's user avatar
  • 157
0 votes
0 answers
32 views

When I use the pow(base, exponent) function in C++ and the exponent is a fraction, I always get 1 as output [duplicate]

I want to calculate the root of a number, so in the function pow(base, exponent) I put 4 as base and 1/2 as exponent. If I use 0.5 instead of 1/2 I get the correct result, 2. I don't want to use the ...
FrancyStyle's user avatar
0 votes
2 answers
207 views

Avoid Infinity value when using Math.pow and comparision with loops

When I do Math.pow(3, num)/num, it is giving me the value if Infinity and when I do modulus of that with 2 it is giving me NaN. I understand NaN is due to Infinity. I am using 300530164787 as the num ...
Gary's user avatar
  • 2,313
0 votes
1 answer
54 views

Why does pow works here

From what i know the function pow works only with double and returns double but in this programm everything works fine and its all in int. i just want to understand like so why even though it only ...
artur anikin's user avatar
1 vote
0 answers
110 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
2 votes
1 answer
115 views

How do I test binary floating point math functions

I implemented the powf(float x, float y) math function. This function is a binary floating point operation. I need to test it for correctness,but the test can't iterate over all floating point. what ...
xiaohuihui's user avatar
0 votes
3 answers
167 views

Incorrect result when using %d placeholder in a pow() function in C

I'm trying to finish some basic coding exercise and I have already figured out how to fix it but I would just really like to understand what's going on. #include <stdio.h> #include <math.h>...
ddp17's user avatar
  • 41
-1 votes
1 answer
232 views

C++ Complex number expression for integrating

I'm trying to implement Monte-Carlo method to solve an integral and can't figure an approximation for my function. double function(double x) { std::complex<double> fz = (pow(-7 * pow(x, 4) - ...
Suspense's user avatar
0 votes
0 answers
93 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
1 vote
1 answer
338 views

int64(math.Pow(2, 63) - 1) results in -9223372036854775808 rather than 9223372036854775807

I am trying to store max and min signed ints of different bits. The code works just fine for ints other than int64 package main import ( "fmt" "math" ) func main() { ...
M Umer Masood's user avatar
-2 votes
3 answers
71 views

Error in true false output in Array Problem

Here's the question: A Narcissistic Number is a positive number which is the sum of its own digits, each raised to the power of the number of digits in a given base. In this Kata, we will restrict ...
Tirtharaj Roy's user avatar
1 vote
1 answer
77 views

Don't understand how nextpow works

Recently I have been looking at how the nextpow(a::Real, x::Real) function works inside. The code is in base/intfuncs.jl of the Julia project. For the case a == 2 there is an optimization as it is ...
Jose Manuel de Frutos's user avatar
0 votes
0 answers
191 views

in vs code sometimes pow(10,i) function gives 99 not 100 as output when i=2? [duplicate]

"pow is a double function" is this the correct explanation if yes then why does sometimes it shows this type of error, why not every time while using it in a loop... this is a code of ...
s3warriors's user avatar
0 votes
0 answers
77 views

How do I raise a number by another number (num1^num2) [duplicate]

This is my code. I get 3^2=1. I have included the math library. case '^': printf("The result is %d\n",(num1^num2)); break;
Aysha Abdalla's user avatar
0 votes
2 answers
77 views

-2.6 to the power of 0.2 outputs #IND00

currently i'm doing my practice for C language and i've found one question about function pow() in C\C++. #include <stdio.h> #include <math.h> int main(){ double k = 0.2; printf(&...
fonabyatzz's user avatar
0 votes
1 answer
126 views

The function pow of math returns several results in several environments

I'm developing a program in C++. I have to perform some calculations with pow of math library. When a run this code: #include <math.h> #include <stdio.h> int main (void) { unsigned long l;...
Felix's user avatar
  • 1
7 votes
2 answers
106 views

Why am I seeing a one-off error with Math.pow(11, 16)?

I have to compute 11^16 for a project at my Uni. Somehow Math.pow(11,16) computes a solution exactly 1 less than WolframAlpha or my other computation method. My code is: public class Test { ...
pezubi's user avatar
  • 75
0 votes
3 answers
149 views

C++ "for" loop with a pow function in it gives incorrect results

I'm studying coding basics, and had to make a code that calculates how many levels of a pyramid could be built with blocks available "x", if each level is squared (e.g. 1st=1, 2nd=4, 3rd=9 ...
Kla Veg's user avatar
  • 13
0 votes
1 answer
38 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
59 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
-4 votes
2 answers
41 views

c power function show wrong result [duplicate]

Here is the problem result Image There result is 3024 but right result will be 3025; what is the problem please help ! thanks for advance.
Nafiul Haque Inan's user avatar
1 vote
2 answers
125 views

Why is multiplication of numbers with floating point inside a loop isn't as precise as outside of it?

I was writing a program to calculate sin(x) with x in [0, 1], using Taylor series that include raising some of its terms to a certain power. Since I'm new to C, I decided to write my own pow() ...
lil_robo's user avatar
0 votes
1 answer
53 views

Computing an array with a given shape containing powers of x = complex(0, 1)

I am trying to create a 9-lines array (shape = (9,)) containing powers of x = complex(0, 1): 1, x, x**2, ..., x**8. I do not know if there is someone who knows what is meant by the statement powers of ...
12666727b9's user avatar
  • 1,015
0 votes
0 answers
28 views

Issue with power function? [duplicate]

I'm working on a function that requires me using a pow function, everything was working fine but I had an issue located in this section of code. This second cout prints 1. it should ouput something ...
Wyatt Williamson's user avatar
0 votes
1 answer
92 views

Why the different results when using external modulus than built-in pow(x, y, mod) in Python 3.9

While watching John Hammond's YouTube video about "Modular Inverses in Python 3 (PicoCTF 2022 #03 basic-mod2)" I discovered the newer version of pow(x, y, mod) function in Python 3.9, which ...
Raspberry Pieman's user avatar
0 votes
1 answer
55 views

Php array to pow numbers revers function problem

<style> .red{color:red;} .green{color:green;} </style> <?php function array2aiflag($inputString){ $arAIFlag = ["AGGR","NOMOVE","COWARD","...
ulusanyazilim's user avatar
2 votes
4 answers
453 views

Power function giving different answer than math.pow function in C

I was trying to write a program to calculate the value of x^n using a while loop: #include <stdio.h> #include <math.h> int main() { float x = 3, power = 1, copyx; int n = 22, copyn;...
Abir Mondal's user avatar
0 votes
0 answers
49 views

How to increase double's precision in c++? [duplicate]

I try to calculating one series, using formula (2^n + 1) / (3^n - 1); In the code below you can see how I do that: #include <math.h> #include <iomanip> using namespace std; // 3....
theneon's user avatar
  • 13
-3 votes
2 answers
144 views

To calculate the cube of using pow [closed]

what is wrong with the code since it is not giving the value for cube #include<stdio.h> #include<math.h> int main(){ int number; printf("Give The Number:\n"); scanf("%d"...
PRERNA's user avatar
  • 7
-1 votes
1 answer
86 views

Why pow() function working correctly, only after saving it to a variable? [duplicate]

I were asked to c-program to accept two variables and print the answer when second variable is raised to the power of first variable. So I coded, #include<stdio.h> #include<math.h> int x,...
ADHIROOBAN D's user avatar
0 votes
1 answer
73 views

How to prevent Sympy from calculating degree in pow

There is an expression: 3^(48*x) Sympy on further calculations will convert it to: 79766443076872509863361^x Perhaps there is some kind of flag that prohibits such horrors.
Andrew Mir's user avatar
1 vote
0 answers
88 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
0 votes
1 answer
79 views

Why is C++ not changing my code's numbers' condition according to pow (-1,i)?

I have C++ code here: #include <iostream> #include <cmath> #include <time.h> using namespace std; int main() { double n,x; cin>>n>>x; ...
Top Factland's user avatar

1
2 3 4 5
14