Skip to main content
4 votes
1 answer
52 views

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....
Colin Leede's user avatar
24 votes
4 answers
3k views

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?...
Jan Schultke's user avatar
  • 44.5k
1 vote
4 answers
292 views

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 ...
Etetherin's user avatar
3 votes
1 answer
261 views

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 ...
Dominic 's user avatar
9 votes
1 answer
186 views

[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 ...
Jan Schultke's user avatar
  • 44.5k
7 votes
2 answers
303 views

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 ...
Jan Schultke's user avatar
  • 44.5k
2 votes
2 answers
248 views

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, ...
Fedor's user avatar
  • 24.9k
4029 votes
35 answers
619k views

Consider the following code: 0.1 + 0.2 == 0.3 -> false 0.1 + 0.2 -> 0.30000000000000004 Why do these inaccuracies happen?
Cato Johnston's user avatar
25 votes
13 answers
3k views

I'm writing a program where I need to parse some configuration files in addition to user input from a graphical user interface. In particular, I'm having issues with parsing strings taken from the ...
Newbyte's user avatar
  • 3,955
3 votes
1 answer
248 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.2k
2 votes
3 answers
228 views

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 ...
Jan Schultke's user avatar
  • 44.5k
2777 votes
33 answers
4.9m views

How can I convert an str to a float? "545.2222" -> 545.2222 Or an str to a int? "31" -> 31 For the reverse, see Convert integer to string in Python and Converting a float to ...
Tristan Havelick's user avatar
2455 votes
36 answers
6.1m views

I want a to be rounded to 13.95. I tried using round, but I get: >>> a 13.949999999999999 >>> round(a, 2) 13.949999999999999 For the analogous issue with the standard library Decimal ...
user avatar
16 votes
2 answers
739 views

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 ...
Fedor's user avatar
  • 24.9k
2021 votes
41 answers
1.8m views

How do I check if a string represents a numeric value in Python? def is_number(s): try: float(s) return True except ValueError: return False The above works, but it ...
Daniel Goldberg's user avatar

15 30 50 per page
1
2 3 4 5
1034