exponent

Custom math functions vs. supplied Math functions?

半世苍凉 提交于 2019-12-02 10:15:54
I am basically making a Java program that will have to run a lot of calculations pretty quickly(each frame, aiming for at least 30 f/s). These will mostly be trigonometric and power functions. The question I'm asking is: Which is faster: using the already-supplied-by-Java Math functions? Or writing my own functions to run? The built-in Math functions will be extremely difficult to beat, given that most of them have special JVM magic that makes them use hardware intrinsics. You could conceivably beat some of them by trading away accuracy with a lot of work, but you're very unlikely to beat the

How to calculate the mod of large exponents?

喜夏-厌秋 提交于 2019-12-02 08:53:04
问题 For example I want to calculate (reasonably efficiently) 2^1000003 mod 12321 And finally I want to do (2^1000003 - 3) mod 12321. Is there any feasible way to do this? 回答1: Basic modulo properties tell us that 1) a + b (mod n) is (a (mod n)) + (b (mod n)) (mod n) , so you can split the operation in two steps 2) a * b (mod n) is (a (mod n)) * (b (mod n)) (mod n) , so you can use modulo exponentiation (pseudocode): x = 1 for (10000003 times) { x = (x * 2) % 12321; # x will never grow beyond

“AttributeError: exp” while using numpy.exp() on an apparently ordinary array

旧时模样 提交于 2019-12-02 05:05:59
问题 I'm running some code where in the middle I have this line: e2 = np.exp(dot1) If I print out the value dot1 , it is: [[-30.248272500719885]] But the line produces this error: e2 = np.exp(dot1) AttributeError: exp If I go to a new window and simply code this: print numpy.exp([[-30.248272500719885]]) there are no problems... then what's wrong with the above code? Edit I've added some surrounding code to the original line: import numpy as np # LOTS OF CODE INCLUDING THE INITIALIZATION OF ARRAYS

GLSL: pow vs multiplication for integer exponent

孤者浪人 提交于 2019-12-02 04:23:36
问题 Which is faster in GLSL: pow(x, 3.0f); or x*x*x; ? Does exponentiation performance depend on hardware vendor or exponent value? 回答1: While this can definitely be hardware/vendor/compiler dependent, advanced mathematical functions like pow() tend to be considerably more expensive than basic operations. The best approach is of course to try both, and benchmark. But if there is a simple replacement for an advanced mathematical functions, I don't think you can go very wrong by using it. If you

How to calculate the mod of large exponents?

我与影子孤独终老i 提交于 2019-12-02 03:34:05
For example I want to calculate (reasonably efficiently) 2^1000003 mod 12321 And finally I want to do (2^1000003 - 3) mod 12321. Is there any feasible way to do this? Basic modulo properties tell us that 1) a + b (mod n) is (a (mod n)) + (b (mod n)) (mod n) , so you can split the operation in two steps 2) a * b (mod n) is (a (mod n)) * (b (mod n)) (mod n) , so you can use modulo exponentiation (pseudocode): x = 1 for (10000003 times) { x = (x * 2) % 12321; # x will never grow beyond 12320 } Of course, you shouldn't do 10000003 iterations, just remember that 2 1000003 = 2 * 2 1000002 , and 2

Strange behavior of R

我们两清 提交于 2019-12-02 02:54:22
So, I have the following code in R: y a <- -0.1 test <- (1/((y+as.numeric(!y))*(a-1))) test test^a -0.9090909^a Giving me the output: > y [1] 0.00000000 0.06024096 0.00000000 0.01098901 0.00000000 0.00000000 [7] 0.01829268 0.00000000 0.06976744 0.00000000 0.04380665 0.01351351 [13] 0.00000000 0.00000000 0.00000000 0.00000000 0.00310559 0.00000000 [19] 0.00000000 0.00000000 0.09957447 0.00000000 0.03738318 0.00000000 > a <- -0.1 > test <- (1/((y+as.numeric(!y))*(a-1))) > test [1] -0.9090909 -15.0909091 -0.9090909 -82.7272727 -0.9090909 [6] -0.9090909 -49.6969697 -0.9090909 -13.0303030 -0

“AttributeError: exp” while using numpy.exp() on an apparently ordinary array

坚强是说给别人听的谎言 提交于 2019-12-02 02:27:03
I'm running some code where in the middle I have this line: e2 = np.exp(dot1) If I print out the value dot1 , it is: [[-30.248272500719885]] But the line produces this error: e2 = np.exp(dot1) AttributeError: exp If I go to a new window and simply code this: print numpy.exp([[-30.248272500719885]]) there are no problems... then what's wrong with the above code? Edit I've added some surrounding code to the original line: import numpy as np # LOTS OF CODE INCLUDING THE INITIALIZATION OF ARRAYS y and self.g # AND getting into into a loop with index i for j in range(m): print "Calculating beta for

GLSL: pow vs multiplication for integer exponent

孤街浪徒 提交于 2019-12-02 00:52:34
Which is faster in GLSL: pow(x, 3.0f); or x*x*x; ? Does exponentiation performance depend on hardware vendor or exponent value? While this can definitely be hardware/vendor/compiler dependent, advanced mathematical functions like pow() tend to be considerably more expensive than basic operations. The best approach is of course to try both, and benchmark. But if there is a simple replacement for an advanced mathematical functions, I don't think you can go very wrong by using it. If you write pow(x, 3.0) , the best you can probably hope for is that the compiler will recognize the special case,

Why does exponential notation with decimal values fail? [closed]

∥☆過路亽.° 提交于 2019-12-01 21:46:33
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Conventionally 1e3 means 10**3 . >>> 1e3 1000.0 >>> 10**3 1000 Similar case is exp(3) compared to e**3 . >>> exp(3) 20.085536923187668

limit the exponential notation decimal place to 4 in javascript

妖精的绣舞 提交于 2019-12-01 20:41:36
问题 How to limit the decimal place to 4 in javascript with this type of values? the e is the exponent since I am using power of ten values. toFixed() doesn't seem to work. 1.0531436913408342e-7 -5.265718456704172e-7 8.425149530726674e7 回答1: Try: Math.round(val*10000)/10000 回答2: Try this method: value.toPrecision(1 + 4) for 4 decimal digits. 回答3: use the force, Luke! There's actually a javascript method specifically for limiting the number of decimal places to show in exponential notation: *numObj