1,130 questions
0 votes
0 answers
90 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
177 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
183 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
106 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
357 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
336 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
61 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
73 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
120 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
409 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
62 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
119 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 ...
0 votes
5 answers
177 views
If I can't use subtraction to test whether addition has overflowed, then how can you use division to test whether multiplication has overflowed?
int sum = x+y; sum-x == y; If sum overflows, then sum-x will not be equal to y and overflow is detected. But if sum has not overflowed, then sum-x==y is equal to y. Then why is this logic not used? ...
0 votes
1 answer
133 views
Intentional Overflow [duplicate]
I'm wondering if it is allowed in C++ to use overflow on purpose. In specific I want to increase a counter every cycle and when uint32_max is reached start from 0. In my mind the easy way would be: ...