# Questions tagged [floating-point]

A method of representing numbers by a fixed number of significant digits, and the exponent of some base number. They are characterized in the form ${(significant digits)}*base^{exponent}$. Typically, numbers are represented with respect to base = 2 (binary).

110 questions
Filter by
Sorted by
Tagged with
173 views

### log-sum-exp trick for signed/complex numbers

I need to evaluate a sum of values that are on many different orders of magnitude in scale but might be signed. I’ve had great luck with the “log-sum-exp” trick for an unsigned version of my problem, ...
93 views

### Numerical stability in the product of many matrices

I have to calculate in numpy the matrix-product of many matrices (~400). Are there common practices to increase numerical stability? If this is relevant, the matrices are $300\times 300$ orthogonal ...
79 views

### Is expm1 the right primitive?

I'm writing some code to calculate $\int_0^1 e^{ax} \mathrm{d} x$. Annoyingly there does not seem to be a way of doing this without if statements: ...
44 views

### Matrix multiplication not working in Scilab

I entered an instruction to calculate the coordinates of a vector after a change of basis in order to repeat it many times with various vectors. X0=[1;1/2] is a ...
72 views

### How can I calculate the exponential integral?

(I originally asked this in a different exchange.) I'm writing a program that uses the prime-counting function. Right now, I'm using x/log(x), but I want to ...
48 views

### Evaluate Nth root of a rational to a correctly rounded float

Excuse my lack of vocabulary for I have no formal training in this field, which is also why I ask this question - it may be trivial or it may be impossible. I want to evaluate an expression in the ...
70 views

2k views

### How to generate Poisson-distributed random numbers quickly and accurately?

I have attempted to create Poisson-distributed random numbers, seeing that it is not so easy as the simple multiplicative algorithm works accurately only if the mean is less than 500. Using logarithms ...
45 views

### Quick evaluation of floating point Absolute Error

I need to to find a quick and dirty way to estimate the absolute error introduced by a series of agebraic operations of IEEE single precision floating point numbers, a pessimistic result is ok. The ...
384 views

### How can I interpolate $z_t = x(1-t)+y t$ with single-precision floats so that it satisfies $x\leq z\leq y$, $z_0=x$, $z_1=y$?

Given two (here and below: single-precision, IEEE 32-bit floats) normalized floating-point numbers $x, y$ (perhaps of reasonable range: my counterexamples don't have unusual magnitudes), and another ...
83 views

### Kahan Summation for Three-Term Recurrences

Kahan summation applies to summation problems, but not to three-term recurrence relations. However, a three-term recurrence shares many of the features of a summation-albeit with a rescaling step at ...
204 views

### Does mean removal increase accuracy of numerical differentiation?

I wish to compute the derivative of a vector through numerical differentiation. Let's say, we use a standard 2nd order central difference scheme, to arrive at a differentiation matrix, and apply it on ...
840 views

### Improve numeric stability of subtraction in C++ [closed]

I'm writing a matrix library in c++. After some debugging I found that a simple double difference is not zero for two "equals" numbers. This is due how double are represented in a computer of course. ...
485 views

### How To Calculate Theoretical CPU FLOPS? [duplicate]

I actually find the formulae for peak theoretical performance: Node performance in GFlops = (CPU speed in GHz) x (number of CPU cores) x (CPU instruction per cycle) x (number of CPUs per node) CPU ...
217 views

### Any FOSS MATLAB/Octave toolbox for high-speed variable precision arithmetic?

I need to use variable precision arithmetic in MATLAB for an expensive set of computation. The vpa function provided by the symbolic math toolbox is very slow. I found a non-free alternative toolbox ...
1k views

### Are BLAS implementations guaranteed to give the exact same result?

Given two different BLAS implementations, can we expect that they make the exact same floating point computations and return the same results? Or can it happen, for instance, that one computes a ...
2k views

### Testing equality of two floats: Realistic example

When does it typically make sense in programming to be testing the equality of two floating point numbers? i.e. a == b where both a & b are floats. My ...
91 views

I'm looking to numerically evaluate $\log f_p(z)$ and its derivative $f^\prime_p(z)/f_p(z)$ accurately and efficiently in floating-point, where $$f_p(z)=\int_0^\infty r^{p-1} \exp\left(-\tfrac{1}{2} ... 2answers 363 views ### Can floating point error (in FFTW3) cause non-deterministic behavior? I am solving a numerical optimization problem with my own L-BFGS (implemented in c++). The problem has \approx 10^6 optimization parameters. To find the objective function gradient, I am taking a ... 1answer 71 views ### RNG float range for metropolis monte carlo I have a robust RNG that generates random 32-bit (unsigned) ints. As is probably well known, for metropolis MC simulation, a random number between 0 and 1 is needed to determine acceptance/rejection ... 4answers 321 views ### Small, unpredictable results in runs of a deterministic model I have a sizable model (~5000 lines) written in C. It is a serial program, with no random number generation anywhere. It makes use of the FFTW library for functions using FFT - I do not know the ... 1answer 481 views ### Fortran round-off error with floating point operations I have simple code, which flags nodes with in region enclosed by cylinder. On implementing the code, the result is mild tilt of the cylinder observed case with \theta=90^{\circ}. The algorithm for ... 1answer 149 views ### Where does the floating point error come from? (Finite difference using matrix multiplication versus shifts and adding.) In Julia it appears that one picks up some error terms when doing finite differences using matrix multiplication versus shifts and addition. ... 1answer 90 views ### Numerical computation of the complex elliptic integral E(k) for medium |k| I have implemented Carlson's algorithm for E(k) from Numerical computation of real or complex elliptic integrals (available from ArXiv eprint, see also DLMF). It is essentially his formula (46) ... 4answers 546 views ### Why is \exp(\ln(x))-x\neq0 in floating point arithmetic? Analytically, the expression$$\exp(\ln(x))-x \enspace,$$should give 0. However, in Matlab, it does not. x = linspace(1, 10, 10); exp(log(x)) - x; for x \in ... 2answers 1k views ### Stabilizing a 3x3 real symmetric matrix eigenvalue calculation I have many 3x3 real symmetric matrices for which I need to determine the eigenvalues. Wikipedia gives a nice non-iterative algorithm for this case, which I have translated into C++: ... 3answers 143 views ### Accurate computation of the current time in time integrator I implement Runge--Kutta method for time integration of the system of nonlinear conservation laws$$ u_t + f(u)_x = 0.  As the system is nonlinear, we have to recompute time step ...
I was told by a class mate that the smallest exponent that we can represent by a single-precision floating-point number (which uses 8 bits for the exponent) is $-126$ and the greatest is $127$. I ...
I'm reading the book "A First Course in Numerical Methods" by U. Ascher and C. Greif, and in the 2nd chapter it's written that ... we associate $x$ a floating point representation $fl(x)$ of the ...