15,500 questions
4
votes
1
answer
52
views
Why does this PyTorch model produce non-identical outputs on identical inputs even with fixed random seeds?
I am running inference on a trained PyTorch model using the same input tensor, fixed random seeds, and evaluation mode enabled.
import torch
torch.manual_seed(42)
torch.cuda.manual_seed_all(42)
model....
1
vote
4
answers
292
views
Why doesn't my float comparison work in C?
My expected outcome is that I'm able to compare floats up to the sixth decimal point. The actual results are that they that it's incorrect, only sometimes though.
Bonus if you can tell me why without ...
24
votes
4
answers
3k
views
What is the difference between iszero(x) and x == 0 for floating types?
C23 added the classification macro iszero for testing whether an argument value is zero, specified like:
int iszero(real-floating x);
What is the difference between using iszero(x) and writing x == 0?...
3
votes
1
answer
261
views
How to deal with large numbers and imprecision in python?
Example:
i = 292893227695
j = 8*i**2 + 1
k = math.sqrt(j)
print(j)
print(k)
print(k.is_integer())
gives output
686291542636760920104201
828427149867.0
True
Even though k is not an integer.
More ...
9
votes
1
answer
186
views
Does std::to_chars ever really disambiguate using round_to_nearest?
[charconv.to.chars] says the following:
The functions that take a floating-point value but not a precision parameter ensure that the string representation consists of the smallest number of ...
7
votes
2
answers
303
views
What is the difference between fmax, fmaximum, and fmaximum_num, and which one should I use?
C23 now has four different ways of computing the maximum or minimum of two floating-point numbers:
x > y ? x : y for maximum (or the other way for minimum)
fmax / fmin
fmaximum / fminimum
...
2
votes
2
answers
248
views
diverging std::atan2's unit of least precision
I write a cross-platform program for Windows and Linux, and I would like it to behave as similar on both platforms as possible. I use some mathematics in the program, e.g. std::atan2 function calls, ...
2
votes
3
answers
228
views
What are examples of non-finite float values other than infinity and NaN?
C23 §5.2.5.3.3 [Characteristics of floating types <float.h>] paragraph 8 says:
Floating types shall be able to represent signed zeros or an unsigned zero and all normalized floating-point ...
2
votes
2
answers
139
views
Difference in Double representation between Kotlin and Swift
In Kotlin, if you do println(String.format("%.17f", 10.45)), you will see 10.45000000000000000 in the output.
In Swift, if you do print(String(format: "%.17f", 10.45)) you will see ...
3
votes
1
answer
248
views
Accurate computation of the inverse gamma function with the standard C math library
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 ...
4
votes
3
answers
255
views
PHP 8.4 rounding gives different result than 8.2
I am in the process of upgrading our code from php 8.2 to 8.4
I noticed we are getting some test failures because of round() returning different values than expected. Ultimately the problem could be ...
4
votes
1
answer
143
views
Invalid Operation with Arm64 fcmp and simd
Consider the following snippet:
ldr q0, [x0]
cmeq v0.16b, v0.16b, #0
shrn v0.8b, v0.8h, #4
fcmp d0, #0.0
This is a common way to implement functions such as strlen with SIMD. According to the Arm64 ...
Advice
2
votes
10
replies
190
views
What is the minimum range of the quotient assigned by `remquo()`?
Is the minimum range that remquo(x, y, quo) assigns *quo [-7 ... +7]?
Is not, what is the minimum compliant range?
double remquo(double x, double y, int *quo); has the following description:
The ...
16
votes
2
answers
739
views
Parsing of small floats with std::istream
I have a program that reads the coordinates of some points from a text file using std::istringstream, and then it verifies the correctness of parsing by calling stream's operator bool().
In general it ...
-4
votes
3
answers
317
views
the pow() function isn't accurate
I read Calculating very large exponents in python , and Ignacio Vazquez-Abrams's answer was to use the pow() function
So , I run the following command in Python 3.9.6 :
print(int(pow(1.5,96)))
and ...