1,132 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
11
votes
4
answers
1k
views
Why don't C overflow checks use CPU flags?
Both amd64 and arm64 architecture processors have an overflow flag. However, in C, the most common method to detect whether an operation causes overflow/underflow is to make functions like these:
int ...
Advice
1
vote
5
replies
106
views
Integer arithmetic in R, allowing integer overflow
By default, when a result of integer operation would not fit into R's 32bit integer type, we get a warning and the result is NA. E.g.:
1920912463L
# 1920912463 (valid integer)
1920912463L + ...
0
votes
0
answers
96
views
Detecting Unsigned Addition Overflow with Signed Integers in 2's complement
I'm trying to detect if there is unsigned overflow when adding the 2's complement representation of 2 signed integers (using a custom SignedInteger class that wraps modulo 2**bits if the value leaves ...
5
votes
2
answers
179
views
Why (-1 - int.MinValue) does not cause integer overflow?
Why C# checked keyword does not treat -1 - int.MinValue as overflow?
int x = int.MinValue;
int y;
checked {
// Overflow. 2^31 cannot be represented in signed integer.
try { y = -x; } catch (...
4
votes
2
answers
191
views
integer comparision; difference in behavior between Clang and GCC 12
I'm seeing a strange (to me) difference in behavior between Clang and GCC when comparing an integer with its negation. Also, pre-v12 GCC behaves like Clang.
Code is below, but also here's a live link ...
4
votes
2
answers
110
views
What to do when the pandas error position overflows?
So, I'm experimenting with pandas with the IMDB files, especially title.basic.tsv. When trying to parse the runtimeMinutes column to "Int64", I get an error
ValueError: Unable to parse ...
6
votes
4
answers
361
views
How do you figure out how large an integer you will need for an operation in embedded systems?
For example, if I want to add two unsigned 8-bit integers together, I know I will need to store the result in a 16-bit integer. Otherwise, I run the risk of overflowing.
This problem gets more ...
3
votes
4
answers
372
views
How to clip to max an integer overflow using numpy or opencv
I have an array of the form a = np.array([1], dtype='uint8').
Now if I add 255 to a it will overflow and be np.array([0]).
Is there a built-in way to "clip" to value to 255?
NumPy has the ...
1
vote
1
answer
62
views
Numpy array from the image is not squaring right
I have this program that is supposed to select one color channel from an image, and square each element elementwise. However, it is not returning any results greater than the values in the first array?...
0
votes
1
answer
75
views
InferSharp does not detect buffer overrun in C# array access beyond bounds
I'm using InferSharp to analyze a compiled .NET 6.0 C# project for potential issues. However, it does not detect a buffer overrun in the following code:
namespace Buffer_overflow
{
public class ...
4
votes
3
answers
187
views
Overflow arithmetic in C programming language
My platform is x86_64, and assume there are 3 variables whose types are all uint16_t:
uint16_t a, b, c;
And for the following two code snippets:
(1)
uint16_t tmp = b - a;
uint16_t result1 = c - tmp;
...
2
votes
3
answers
122
views
Confused by difference between expression inside if and expression outside if
Context:
I want to verify the fact that under 32-bits, Ox8000 0000 - 1 = Ox7FFF FFFF, so if both of them are interpreted as signed integers, the sign will change from negative to positive.
Here goes ...
0
votes
0
answers
441
views
overflow encountered in matmul, what can I do?
I am currently using an open source Python package called snompy (https://github.com/TomVincentUK/snompy). While implementing the package, a function that defines the transfer matrix returns an ...
0
votes
0
answers
63
views
Is integer overflow defined behavior in Fortran? [duplicate]
According to the C standard, signed integer overflow is undefined behavior. Fortran integers are signed integers. Does the Fortran standard mandate how overflow should be treated? In practice it seems ...
-3
votes
2
answers
130
views
integer overflow in expression of type ‘int’ results in ‘1’ [-Woverflow]
I want to understand more about int overflow in C++ on a 64-bit system. So I would like to stick to int for my understanding without casting / extending the type to unsigned or 64-bit and I am on ...