Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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).

0
votes
0answers
35 views

Representatoins in floating point arithmetic

I read 'Pivoting for LU Factorization'. On page 3, I found something incomprehensible: When these computations are performed in floating point arithmetic, the number $2−10^{-20}$ is not represented ...
6
votes
2answers
231 views

Is Highams' computation of mean worth the price?

In Accuracy and Stability of Numerical Algorithms, equation 1.6a, Higham gives the following update formula for the mean: $$ M_{1} := x_1, \quad M_{k+1} := M_{k} + \frac{x_k - M_k}{k} $$ Ok, one ...
4
votes
2answers
98 views

SLATEC Routine Computes Givens Rotation in Unexpected Way

Some Background I am working on a C++ translation of a SLATEC routine, R1UPDT, which performs a Givens rotation: $$r = \frac{1.0}{\sqrt{a^2 + b^2}}$$ Usually, ...
5
votes
0answers
130 views

Any way to avoid catastrophic cancellation when computing the discriminant of a quadratic function?

Homework disclaimer... The task: We are using the following algorithm to solve the quadratic equation $x^2+2px+q=0$: $x_1=|p|+\sqrt{p^2-q}\mathtt{;}$ $\mathtt{if}\,p>0\,\mathtt{then}\,...
4
votes
0answers
77 views

Comparing sum of floating points

I am currently working on a numerical algorithm involving a lot of floating point arithmetic, involving some badly conditioned problem sets. I am using the relation $|x - y| / (\max(|x|, |y|, 1)) \...
1
vote
0answers
33 views

Why is the method of im2col with GEMM is more efficient than the method of direction implementation with SIMD in CNN

The convolutional layers are most computationally intense parts of Convolutional neural networks (CNNs).Currently the common approach to impement convolutional layers is to expand the image into a ...
5
votes
2answers
127 views

Fast and Numerically Stable Pairwise Distance Algorithms

I'm looking for resources on fast, numerically stable pairwise euclidean distance algorithms. In particular, suppose $A \in \mathbb{R}^{M \times D}$ and $B \in \mathbb{R}^{N \times D}$ are two sets of ...
7
votes
2answers
124 views

Integer operations vs floating point operations

I have been working with an algorithm, which uses additions of floating point vectors, (sparse matrix of floats)x(dense vector of floats) dot products I recently found out that I can get the same ...
6
votes
1answer
196 views

Is it possible to proof a-b+b = a for all double floating-point numbers?

I want to know whether the equation : a-b+b = a is always true for a, b belongs to double precision floating-point number and |a|>=|b|. If the equation is true, how can I proof it? If not, what ...
6
votes
2answers
385 views

Matrix multiplication accuracy Matlab vs Python

I am translating some Matlab code into Python and I having some problems regarding matrix multiplication accuracy. Assuming we have following data: ...
3
votes
1answer
195 views

Time complexity of $l_2$-norm of a vector

What is the complexity (in flops, floating-point operations) of taking the $l_2$-norm of vector $\mathbf{v}\in\mathbb{R}^n$ (or $\mathbf{v}\in\mathbb{C}^n$ if a difference exists). We have the ...
3
votes
0answers
84 views

Stabilizing online average calculation

In Knuth, the following method for computing an average is presented: \begin{align*} M_{n} = M_{n-1} + (x_{n} - M_{n-1})/n \end{align*} (See here, if you don't have TAOCP.) Assuming the samples all ...
3
votes
1answer
318 views

Finite difference method basic implementation on Octave

Trying to study the error of FDM for a second order derivative versus step size I calculated the coefficients and validated them, but the output has errors for small step sizes. The function in ...
2
votes
2answers
104 views

Evaluating $\log(\exp(x)+1)$ for negative $x$

With double precision, I get $\log(\exp(-3)+1)=0.048587351573741958$, which already has $4$ incorrect digits, and $\log(\exp(-30)+1)=9.348... \times10^{-14}$, which only has two correct digits. What ...
2
votes
2answers
126 views

Fixing catastrophic cancellation in velocity formula

In Writing Scientific Software: A Guide to Good Style, several disasters are mentioned including a missle defence system which led to deaths at a US base in Saudi Arabia in 1991. The error was caused ...
7
votes
1answer
116 views

Does the IEEE-754 standard mandate that exp2 is rounded correctly?

The IEEE Standard for Floating-Point Arithmetic section "9.2 Recommended correctly rounded functions" lists functions that are recommended (but not required) by a language standard to provide, among ...
4
votes
2answers
111 views

Intervals where the sign of a polynomial can be computed reliably

This is a follow-up of a previous question. Let $p$ be a polynomial with floating-point coefficients. Is there a method for finding intervals where evaluating $p$ in floating-point arithmetic always ...
4
votes
1answer
94 views

Associativity in floating point arithmetic failing by two values

Cross-posting from math.stackexchange, since there might be people here familiar with this topic. Assume working in floating point arithmetic with finite precision, bounded exponent and rounding to ...
6
votes
3answers
122 views

Accurate evaluation of the sign of a polynomial

Let $p$ be a polynomial with floating-point coefficients and let $a$ be a floating-point value. Is there a method for accurately evaluating the sign of $p(a)$ in floating-point arithmetic? I don't ...
6
votes
1answer
85 views

Stable computation of ratio of sums of large numbers

I have two sets of large positive numbers $a_1,\ldots,a_n$ and $b_1,\ldots,b_n$. By 'large' I mean of the order of $10^{10}$. I want to calculate the ratio $$R = \frac{a_1 - a_2 + \cdots +(-1)^{n+1}...
0
votes
2answers
890 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 ...
3
votes
0answers
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 ...
5
votes
1answer
361 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 ...
1
vote
0answers
80 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 ...
7
votes
1answer
200 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 ...
1
vote
1answer
558 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. ...
3
votes
0answers
434 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 ...
2
votes
1answer
161 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 ...
16
votes
3answers
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 ...
9
votes
6answers
1k 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 ...
3
votes
1answer
88 views

Numerical evaluation of gaussian-like integral expressible as a recurrence relation

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} ...
6
votes
2answers
292 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 ...
1
vote
1answer
66 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 ...
11
votes
4answers
280 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 ...
0
votes
1answer
365 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 ...
6
votes
1answer
136 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. ...
7
votes
1answer
84 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) ...
6
votes
4answers
438 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 ...
4
votes
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++: ...
2
votes
3answers
142 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 ...
0
votes
1answer
103 views

Why the greatest exponent that can be represented in single-precision floating-pointer numbers is 127 (and not 128)?

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 ...
1
vote
0answers
37 views

t digits are used to represent the mantissa in floating-point system, but rounding unit is calculated for doubles with 53 bits

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 ...
2
votes
1answer
69 views

Is more robust to digit cancellation the sum operator or the mean operator?

Note: this question is not strictly related to Matlab or any other environment (even though I would prefer that you refer to my Matlab code). I've n = 10000 ...
1
vote
1answer
42 views

How to compute $\mathrm{proj}_{SDP}(C\odot X)./C$ without numerical problems?

I have a matrix, $X$, it is symmetric. I project $C \odot X$ and $D\odot X$ to semidefinite cone. $C$ is a Gramian matrix with some elements near zero and of course semidefinite, with one row and ...
1
vote
1answer
1k views

Addition and subtraction of two floats in Python

Yesterday I was wondering how floats are handled in a computer and what they look like in binary... I learnt about the single-precision floating-point and I tried to see the limit of that format... I ...
8
votes
0answers
404 views

Implementing std::nextafter: Should denormals-are-zero mode affect it? If so, how?

This might be the wrong stackexchange site for this question. math.SE, cs.SE, programmers.SE, and of course stackoverflow are all possibilities. I'm hoping to reach an audience that might actually ...
8
votes
1answer
502 views

Hardware performance, floating point functions

First of all, hope I've found the right forum for this question, if I haven't please pass me on to a one which would fit better. Out of curiosity from an argument with someone who may or may not be ...
7
votes
2answers
297 views

Sum over very small exponentials: Underflow

I am trying to compute (in C) a sum like $S = \sum_i \exp( - a_i )$, where $10^{4} < a_i < 10^{5}$ are approximately normal distributed. So even if I do the Log-Sum-Exp trick $S = \exp(\...
2
votes
1answer
54 views

Comparing two versions of the same hydrodynamic code and their error

So I have two versions of a hydrodynamic code that has the same underlying physics. Lets call them code A and B. However code B is more optimized and more object oriented. I was trying to compare the ...
1
vote
1answer
69 views

How do I add some floating point numbers, keeping numerical accuracy in mind?

I am solving a problem involving the line with the set of points $(x_3,y_3)$ that are equidistant to two given points $(x_1,y_1)$ and $(x_2,y_2)$. The equation for this line is $$(x_3 - x_1)^2 + (y_3 ...