Skip to main content
Filter by
Sorted by
Tagged with
Best practices
0 votes
8 replies
81 views

I have this question that I want to test in code: if we have x1, x2, x3, x4 (all float16) and f() = (x1 + x2) * x3 - x4, I want to know whether the machine rounds after each operation or calculates ...
Kim Raven's user avatar
4 votes
1 answer
283 views

The inverse of the gamma function over the reals is multivalued with an infinite number of branches. This self-answered question is about the principal inverse of the gamma function, Γ0-1(x), whose ...
njuffa's user avatar
  • 27.4k
0 votes
1 answer
324 views

I have the following code in my Fortran program, where both a and b are declared as REAL (KIND=8): a = 0.12497443596150659d0 b = 1.0 + 0.00737 * a This yields b as 1.0009210615647672 For comparison, ...
sgfw's user avatar
  • 356
1 vote
0 answers
101 views

My understanding is that R uses IEC 60559 rounding with "Round to nearest, ties to even", but it does not appear to be generating valid results. For decimal part .535 rounded to 2 places, my ...
simpleuser's user avatar
  • 1,711
1 vote
1 answer
125 views

I need to compute ceil(log_N(i)) where log_N is the log with positive integer base N and i is also a positive integer. The straight forward python implementation using floating point math fails at ...
user1816847's user avatar
  • 2,156
1 vote
0 answers
88 views

If I run x=0:0.1:1; x==0.2, I get equality at the third element (as expected). However, if I change it to x=-1:0.1:1; x==0.2 I no longer get any hits. Why the change? (I am familiar with some details ...
magnesium's user avatar
  • 639
0 votes
1 answer
64 views

My goal is to implement a CDF (cumulative distribution function) for the Standard Normal Distribution and to do so with the best possible numeric accuracy. This is my starting point: (1 + erf(x / sqrt(...
Raymond Hettinger's user avatar
4 votes
1 answer
125 views

Question I was wondering if there is a numerically accurate way to compute sign(a² - b * c) * sqrt(abs(a² - b * c)) with floating point arithmetics because it suffers from (ordered from most to least ...
MothNik's user avatar
  • 141
1 vote
0 answers
111 views

The below code is able to learn the generic pattern and it is able to predict as expected: torch::manual_seed(42); torch::nn::Sequential net( torch::nn::Linear(300, 301), torch::nn::...
Uriel Herrera's user avatar
0 votes
3 answers
176 views

One should not use == to compare real numbers, every C# developer knows that. Then why the Double.CompareTo method, from the framework, is implemented this way for checking equality? public int ...
paradise's user avatar
  • 550
-1 votes
5 answers
287 views

Is it possible to format floating point numbers with sed to extend to equal precision of e.g. 8 digits after the decimal point? Because this problem is part of a bigger context, it is essential to use ...
Zaphod Beeblebrox's user avatar
3 votes
2 answers
258 views

I'm trying to write a function which returns the coefficients of the nth legendre polynomial. // store previous polynomials to make the recursive process faster unordered_map<int, vector<double&...
haifisch123's user avatar
0 votes
3 answers
207 views

I encountered a problem. The code is as follows: float a = 2.f; float t = 0.0000025f; float b = a + t; float c = b - a; printf("b = %.8f\n", b); printf("c = %.8f\n", c); The ...
Zhixiong Xiao's user avatar
0 votes
2 answers
105 views

I fill a numpy array with 0 or 1 depending if a computed array indexed value is more or less than a given value. This results in an array of zeros and ones. Matplotlib doesnt think so The comparison ...
Jeff Secor's user avatar
4 votes
4 answers
188 views

#include <stdio.h> void get_eps(float *eps) { *eps = 1.0f; while ((1.0f + *eps / 2.0f) != 1.0f) { *eps /= 2.0f; } } int main(){ float eps; get_eps(&eps); ...
Marc's user avatar
  • 41
0 votes
0 answers
79 views

In SQL Server Management Studio: DECLARE @Amount FLOAT SELECT SUM(Amount) FROM Docs WHERE DocID IN (104482, 104483, 104484, 104486, 104489, 104491, 104493) -- displays in results window 178457,05 ...
Manolis GRS's user avatar
5 votes
1 answer
224 views

This is a self-answered question, as encouraged on Stackoverflow for sharing knowledge. As such, it is a follow-on to my previous self-answered question about the accurate computation of the ...
njuffa's user avatar
  • 27.4k
3 votes
1 answer
289 views

This is a self-answered question, as encouraged on Stackoverflow for sharing knowledge. As such, it is a follow-on to my previous self-answered question regarding accurate computation of the principal ...
njuffa's user avatar
  • 27.4k
2 votes
1 answer
465 views

The exact value of float 0.7f is 0.69999... so I thought the result of 0.7f * 100f would be something below 70, like 69.99999... But the result is exact 70. Does float multiplication involve such ...
yahoic's user avatar
  • 23
2 votes
1 answer
521 views

Neumaier summation is an improvement of Kahan summation for accurately summing arrays of floats. import numba as nb @nb.njit def neumaier_sum(arr): s = arr[0] c = 0.0 for i in range(1, ...
Simd's user avatar
  • 21.6k
0 votes
1 answer
95 views

I have a SQL Server database from which I can read integer values of (way) over 2^24 from a column that has datatype float. This confuses me since these values should be to big/lengthy to be ...
gebruiker's user avatar
  • 125
-1 votes
1 answer
83 views

12.7 - 20 + 7.3 = -8.8817841970013e-016 I got this problem when I read Programming in Lua book, and I cannot figure it out how to get zero as the result of the calculation. When I formatted the result ...
Ryal Naufal's user avatar
0 votes
1 answer
104 views

My python program has a busy loop. Within the loop, some delays are calculated in the following fashion: timeout_s: float = args.timeout_s timeout_end_s: float = time.time() + timeout_s while True: ...
KamilCuk's user avatar
  • 147k
0 votes
1 answer
175 views

I had this C++ code: int x; double y; // do sth int z = ceil(x*y); If x = 410, y = 1.1, then z = 452 when it should've been 451. I changed to z = ceil(float(x*y)) and it works. My friend suggests z ...
Le_Square's user avatar
4 votes
5 answers
1k views

[While this is a self-answered question, I will happily upvote and accept any alternative answer that either provides superior accuracy for the same amount of computational work or reduces the amount ...
njuffa's user avatar
  • 27.4k
0 votes
0 answers
39 views

So of course: 1023.1 - 0.1 < 1023 [1] FALSE but... 1024.1 - 0.1 < 1024 [1] TRUE Is this a bug? Is it expected behaviour? Is there some way I can avoid this, such as rounding all my numbers to ...
Johann's user avatar
  • 292
0 votes
1 answer
80 views

In my excel file, I've some calculations. Calculation returns 0,345 and excel convert it to 0,35. I made it in python. Python is returning 0,345, but I want to take 0,35 like Excel. I've tried with ...
user avatar
0 votes
1 answer
105 views

I am thinking about calculating $(1-1/x)^y$ for very large x,y numbers in python. One way todo so, it to use exp(y*log1p(-1/x)), but I am not sure about its accuracy. Are they any results on using ...
user3563894's user avatar
0 votes
0 answers
82 views

I am writing some scripts using MATLAB R2020a and I am having a problem: there are two values I want to assign to a vector z_samples, namely x_samples(l_indexes)./sum(x_samples)(a vector) and ...
Moon Traveler's user avatar
0 votes
1 answer
188 views

I'm attempting to create a Python script that identifies all the unique intersection points, eliminating duplicates, among all the lines passing through a subset of points of a regular grid in 2D or ...
Edoardo Serra's user avatar
1 vote
2 answers
745 views

I have data that represents responses from a 24(?)-bit A/D converter. I am setting up the data to go into a polynomial regression in the function below, but I am getting detrimental amounts of ...
javery's user avatar
  • 41
1 vote
2 answers
254 views

I have the following code, plotting a function on a grid, where the function happens to have a very large integer value: import matplotlib.pyplot as plt from matplotlib.ticker import ScalarFormatter, ...
D.R's user avatar
  • 127
0 votes
1 answer
1k views

I am attempting to convert an .e57 pointcloud into a .las pointcloud but I am running into issues which seem to be caused by accuracy. The following images illustrate the original .e57 in CloudCompare,...
Arjan's user avatar
  • 609
1 vote
3 answers
107 views

For example, as I know, a float point x, which x/n^2 may not be equal to x/n/n, because in x/n/n, which would create an intermediate x/n first. For example: document.write(1.23456789/49 == 1....
wcminipgasker2023's user avatar
6 votes
4 answers
312 views

I have to analyse a large amount of data using Python3 (PyPy implementation), where I do some operations on quite large floats, and must check if the results are close enough to integers. To exemplify,...
kleite's user avatar
  • 337
1 vote
0 answers
195 views

I am trying to do a very simple thing take a square shape 2d array take its transpose multiply the array with its transpose I am trying to perform the above steps in C++ and Python as shown in the ...
skm's user avatar
  • 5,789
0 votes
1 answer
154 views

Please be aware that my question is not "Why do floating numbers lose precision" I am aware that not all fractional parts of a number can sit in binary form. What's really stored is actually ...
MarlonB's user avatar
  • 23
3 votes
1 answer
119 views

I'm trying to sample a variable (SST) as a function of another variable (TCWV) using the function histogram, with weights set to the sample variable like this: # average sst over bins num, _ = np....
ClimateUnboxed's user avatar
3 votes
3 answers
849 views

It is said that any decimal number expressed with 15 digits of precision within the range covered by double-precision floats can be uniquely identified with a particular float. But, that if we include ...
Jagerber48's user avatar
  • 1,205
1 vote
1 answer
100 views

In computers, the math operation of floating numbers is actually processed using the base number and the exponential number separately, and then combine them together. We learn this in our computation ...
Leo's user avatar
  • 37
2 votes
3 answers
322 views

A coworker and I have a disagreement about what can happen when comparing two floating-point numbers that have not been mathematically operated on. i.e. the numbers may have been moved around memory ...
Kai Schmidt's user avatar
0 votes
2 answers
606 views

I have a simple camera based 'modern' OpenGL 3D graphics display, for rendering relatively simple objects that are constructed from collections of specified points, lines and curves (e.g. a cube, ...
DavidH's user avatar
  • 107
1 vote
2 answers
266 views

I'm starting to learn c programming language. I know that floats are represented by having: 1 bit for sign 8 bits for exponent 23 bits for mantissa Does this mean that I can represent precisely only ...
Zaratruta's user avatar
  • 2,325
-4 votes
1 answer
325 views

I decided to multiply two numbers: 1.0 17299991019999108999910899991119999 and as a result , I received in response: 1.729999101999911e+34 Code: print(1.0*17299991019999108999910899991119999) 1....
user avatar
0 votes
1 answer
183 views

Disclaimer: I'm using lua on the table top simulator game, I don't know if this interfere in any kind of way with the "regular work" of lua. I already have a bunch of vectors pre-calculated: ...
Riccardo Di Michele's user avatar
1 vote
1 answer
66 views

The below program calculates 262 + 261 + 260 + ... + 21 + 20. Using double type to store sum: double sum = 0; for (int i = 0; i < 63; i++) { sum += pow(2.0, i); // print("i : $i sum :...
user avatar
0 votes
0 answers
24 views

`ini_set('precision', 18); $number2 = 5.00025051541321; echo ($number2); Output: 5.00025051541321019` What can be the issue and if someone help me to solve that.
Harendra Teli's user avatar
1 vote
0 answers
220 views

First off, let me say that I am aware that we are constrained by the limitations of computer arithmetic and floating point numbers and that 0.8 doesn't equal 0.8, sometimes. I'm curious about ways to ...
Nate's user avatar
  • 11
0 votes
1 answer
61 views

I'm worried that something like 7/2 might become 3.49999999 instead of 3.5 on some computer then round to 3 instead of 4. Is that possible? I need every computer to re-run the same math exactly. That'...
Curtis's user avatar
  • 2,545
3 votes
1 answer
99 views

For example: const n=5; const x=1.23; const y=n-x; document.write(x+y==n); the code about prints true for n=5,x=1.23,y=5-1.23 (value after rounded). I think it is just a "lucky" ...
displaydisplayname's user avatar

1
2 3 4 5
28