exp

Why do I get platform-specific result for std::exp? [duplicate]

谁都会走 提交于 2019-12-05 06:01:01
This question already has an answer here: Is floating point math broken? 31 answers Math precision requirements of C and C++ standard 1 answer I have a program that were giving slithly different results under Android and Windows. As I validate the output data against a binary file containign expected result, the difference, even if very small (rounding issue) is annoying and I must find a way to fix it. Here is a sample program: #include <iostream> #include <iomanip> #include <bitset> int main( int argc, char* argv[] ) { // this value was identified as producing different result when used as

Using AVX instructions disables exp() optimization?

陌路散爱 提交于 2019-12-03 14:42:26
I am writing a feed forward net in VC++ using AVX intrinsics. I am invoking this code via PInvoke in C#. My performance when calling a function that calculates a large loop including the function exp() is ~1000ms for a loopsize of 160M. As soon as I call any function that uses AVX intrinsics, and then subsequently use exp(), my performance drops to about ~8000ms for the same operation. Note that the function calculating the exp() is standard C, and the call that uses the AVX intrinsics can be completely unrelated in terms of data being processed. Some kind of flag is getting tripped somewhere

which method to implement exp function in c? [closed]

守給你的承諾、 提交于 2019-12-02 05:48:48
问题 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 . I want to calculate the error of exp function under finite precision(data type is double). Is taylor series or other special algorithm

which method to implement exp function in c? [closed]

自作多情 提交于 2019-12-02 01:11:56
I want to calculate the error of exp function under finite precision(data type is double). Is taylor series or other special algorithm? Generally, the best way to implement e x is by calling the exp function provided by your computing platform. Failing this, implementing the exp function is complicated and requires several esoteric skills. An implementation typically involves: Testing the input for various special cases, such as NaNs. Multiplying the input by a specially prepared representation of log 2 e, to transform the problem from e x to 2 y , where y = x • log 2 e. Moving the integer

sympy hangs when trying to solve a simple algebraic equation

让人想犯罪 __ 提交于 2019-12-01 20:35:49
I recently reinstalled my python environment and a code that used to work very quickly now creeps at best (usually just hangs taking up more and more memory). The point at which the code hangs is: solve(exp(-alpha * x**2) - 0.01, alpha) I've been able to reproduce this problem with a fresh IPython 0.13.1 session: In [1]: from sympy import solve, Symbol, exp In [2]: x = 14.7296138519 In [3]: alpha = Symbol('alpha', real=True) In [4]: solve(exp(-alpha * x**2) - 0.01, alpha) this works for integers but also quite slow. In the original code I looped over this looking for hundreds of different

Where in the python source code is math.exp() defined?

依然范特西╮ 提交于 2019-11-29 23:27:53
问题 I want to known how to implement the math.exp() function in python. Where in the Python source code is math.exp() defined? 回答1: This one is a little tricky. The math module is implemented in a C module, mathmodule.c. At the end of that file there is a specific Python library structure that defines exp as implemented by math_exp: static PyMethodDef math_methods[] = { # ... {"exp", math_exp, METH_O, math_exp_doc}, but math_exp itself is actually defined via the FUNC1 macro, using the math_1

Why does my Visual C++ .exe project build create .lib and .exp files?

橙三吉。 提交于 2019-11-27 22:04:38
I have a solution consisting of 3 projects. One is a static library, and two are console-based .exe files that depend on and link against this library. Their settings seem to be identical. I build one of them: 1>------ Build started: Project: masksample, Configuration: Debug Win32 ------ 1>Compiling... 1>stdafx.cpp 1>Compiling... 1>masksample.cpp 1>Compiling manifest to resources... 1>Linking... 1>LINK : C:\Users\DarekSz\Praca\cci\Debug\masksample.exe not found or not built by the last incremental link; performing full link 1>Embedding manifest... 1>masksample - 0 error(s), 0 warning(s) ======

Fast Exp calculation: possible to improve accuracy without losing too much performance?

笑着哭i 提交于 2019-11-27 18:34:46
I am trying out the fast Exp(x) function that previously was described in this answer to an SO question on improving calculation speed in C#: public static double Exp(double x) { var tmp = (long)(1512775 * x + 1072632447); return BitConverter.Int64BitsToDouble(tmp << 32); } The expression is using some IEEE floating point "tricks" and is primarily intended for use in neural sets. The function is approximately 5 times faster than the regular Math.Exp(x) function. Unfortunately, the numeric accuracy is only -4% -- +2% relative to the regular Math.Exp(x) function, ideally I would like to have

Fast fixed point pow, log, exp and sqrt

余生长醉 提交于 2019-11-27 17:24:42
I've got a fixed point class (10.22) and I have a need of a pow, a sqrt, an exp and a log function. Alas I have no idea where to even start on this. Can anyone provide me with some links to useful articles or, better yet, provide me with some code? I'm assuming that once I have an exp function then it becomes relatively easy to implement pow and sqrt as they just become. pow( x, y ) => exp( y * log( x ) ) sqrt( x ) => pow( x, 0.5 ) Its just those exp and log functions that I'm finding difficult (as though I remember a few of my log rules, I can't remember much else about them). Presumably,

Deal with overflow in exp using numpy

左心房为你撑大大i 提交于 2019-11-27 08:37:46
Using numpy, I have this definition of a function: def powellBadlyScaled(X): f1 = 10**4 * X[0] * X[1] - 1 f2 = numpy.exp(-numpy.float(X[0])) + numpy.exp(-numpy.float(X[1])) - 1.0001 return f1 + f2 This function is evaluated a huge number of times on an optimization routine. It often raises exception: RuntimeWarning: overflow encountered in exp I understand that operand cannot be stored in allocated space for a float. But how can I overcome the problem? You can use the bigfloat package. It supports arbitrary precision floating point operations. http://packages.python.org/bigfloat/ import