17
votes
Accepted
Is the exponential function, e^x, very expensive to compute in Matlab and harmful to my computer?
Computing the term $e^x$ is definitely significantly more expensive than computing a lower-order polynomial -- say $x^4$. But it may be ten to 100 times more expensive at most, not "crazy" expensive. ...
12
votes
Accepted
Evaluating $\log(\exp(x)+1)$ for negative $x$
Use the (IEEE standard) library function log1p, which should be present in all programming languages. The function log1p(x) ...
9
votes
Is `#define INT_MIN 0x80000000` okay?
This is more of a question appropriate to the CS forums, but here is the short of it: it requires you to know how the compiler parses numbers. In particular, when the compiler sees something like <...
8
votes
Unexpected result when summing sorted (and unsorted) positive floating point numbers
Very interesting problem! I might have a partial answer.
To start, I replicated a simple C++ demo that can reproduce the effect
...
6
votes
Accepted
Best software to do big number calculations quickly
Why not give GMPY2 a try? From the introduction:
gmpy2 is a C-coded Python extension module that supports multiple-precision arithmetic. gmpy2 is the successor to the original gmpy module. The gmpy ...
6
votes
Method to compute $a^n - b^n$
That computation is ill-conditioned anyway when $a$ and $b$ are close. This is not something that you can fix by switching to a different method: any method that uses floating-point computations will ...
5
votes
Accepted
Is `#define INT_MIN 0x80000000` okay?
No it's not OK.
There are no negative literals per-se in C. "-12345" is interpreted as the combination of the positive literal 12345 with the unary minus operator.
0x80000000 is outside the ...
4
votes
Evaluating $\log(\exp(x)+1)$ for negative $x$
If you want to use your own implementation to evaluate the function, take a look on this article. Otherwise, just go with log1p as suggested by @Frederico Poloni in his answer.
For more information ...
3
votes
Accepted
Dynamic tolerance in a conditional loop to obtain maximum precision allowed by machine floating point numbers
You are using the wrong measure for the achievable accuracy. $|x|\mu$ is in some way a lower bound for the error, the smallest increment that would give a different value, so that any smaller ...
3
votes
How can I detect lost of precision due to rounding in both floating point addition and multiplication?
Floating-point exceptions may help you here.
C support varies by implementation (compiler) but see GCC here: https://www.gnu.org/software/libc/manual/html_node/FP-Exceptions.html
Python support is ...
2
votes
How can I detect lost of precision due to rounding in both floating point addition and multiplication?
Normally one does not try to detect loss of precision algorithmically, but rather analyzes and modifies algorithms to assess how they are affected by it.
For instance, in your first example you would ...
2
votes
Problems with first and second complement
Two's complement is always done with a specific bit width in mind, and you use modular arithmetic within that width. Basically, you should ignore that leading 1, it's the output carry and should be ...
2
votes
Summation of trigonometric functions results in error with finite precision
Some thoughts:
How many coefficients (N) are there?
If you are solely interested in the zeroes, you might get away with 'stretching' the functions by a constant factor in amplitude and/or a constant ...
2
votes
What does this definition of two's complement representation of signed integers mean?
The idea is that if you have $n$ bits $b = [b_{n-1}, \ldots, b_0]$, then you can represent $2^n$ different things with them, as all $b_k \in \{0, 1\}$.
You can decide to go for the numbers $0, \ldots,...
1
vote
Method to compute $a^n - b^n$
Here is C++ code comparing the Mathematica computation with three more methods.
naive
automatic finite differences
the method proposed in another answer
One important thing to note: if you make $a$ ...
1
vote
Method to compute $a^n - b^n$
you got pretty close to a good method. Specifically what you want to do is compute a^n*exp(n*log1p(-b/a)) when the values are close together. this will avoid ...
1
vote
Best software to do big number calculations quickly
OP's comment on OP:
yes,numbers are intergers
For arbitrarily large integer calculations, MAPLE is an option worth trying. it has very efficient implementations for a number of such calculations.
1
vote
Best software to do big number calculations quickly
Using something such as numpy.divide, you most likely will see no considerable difference from doing it in C++. Although casting might be something to consider.
C++...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
computer-arithmetic × 37floating-point × 15
precision × 9
optimization × 3
algorithms × 3
symbolic-computation × 3
matlab × 2
numerics × 2
c++ × 2
c × 2
rootfinding × 2
numerical-limitations × 2
linear-algebra × 1
matrix × 1
iterative-method × 1
simulation × 1
software × 1
numerical-modelling × 1
error-estimation × 1
fourier-transform × 1
krylov-method × 1
data-analysis × 1
accuracy × 1
special-functions × 1
inverse × 1