1,130 questions
0
votes
0
answers
89
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 ...
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 ...
6
votes
4
answers
356
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 ...
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?...
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;
...
0
votes
0
answers
407
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 ...
-3
votes
2
answers
118
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
1
answer
131
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:
...
1
vote
2
answers
107
views
Initialize a integral variable to +/- infty for a running min/max in Haskell
In running minimum/maximum problems, the e.g. minimum-so-far is often initialized to \infty in order to guarantee we "capture" every minimum, no matter where it is located.
In Haskell, we ...
1
vote
1
answer
162
views
How to convert float to int in C and then back after performing operations while avoiding overflow?
I am working on a project where I need to implement a Neural Network on a microcontroller in C, and execution time is critical. I am trying to try techniques to speed up the running of the code, and ...
2
votes
1
answer
478
views
It is possible to define that a variable should always saturate on arithmetic operations?
I have a variable on which I do a lot of arithmetic operations.
My code was something like this:
let a: u32 = 3;
let res = (a*2) - 42
I had an overflow when a is too low, so I had to use ...
0
votes
0
answers
218
views
How can I avoid Python overflow in pytorch tensors? EDIT: A tensor insiede softmax function suddely become nan after the second iteration
I'm working with really big tensors from pytorch, and as a result of a certain operation I need my tensor to maintain really big values(which represent some indexes), but obviously overflow makes all ...
5
votes
1
answer
102
views
How do I work around what seems to be integer overflow despite the type being large enough [duplicate]
I am performing the following calculation:
unsigned long long int interval = (ui->spinBox_2->value() * 60 * 60 * 1000) + (ui->spinBox_3->value() * 60 * 1000) + (ui->spinBox_4->value()...
-1
votes
1
answer
182
views
Attempt to multiply with overflow
Rust panicked: attempt to multiply with overflow
I'm trying to make a polynomial for the "AES" encryption algorithm.
The fn new() is meant to construct the bit vector representation of a ...
2
votes
1
answer
106
views
char * vs unsigned char *
So I was playing around with char* and unsigned char* pointers. And I came across this issue:
Code:
#include <stdio.h>
void func(unsigned int max) {
unsigned int* intptr = &max;
...
0
votes
1
answer
115
views
truncate does not support creating files with sizes greater than 2^63-1
Apparently, gnu truncate on my x86_64 system does not support creating files with sizes of size >= 8EiB (= 2^63 Bytes = 9223372036854775808 Bytes).
/usr/bin/truncate: ELF 64-bit LSB pie executable, ...
0
votes
1
answer
566
views
How can I implement the overflow flag in Logisim without having access to the second last carry?
In the pic of the ALU, I've implemented the logic to calculate the zero, negative and carry flags. But I can't figure out how to implement the overflow flag without using the second last carry (carry-...
1
vote
1
answer
63
views
Is there any chance that simplified forms of certain mathematical expressions throw overflow errors while complex ones dont?
I was attempting the #69 problem of leetcode, which involves finding square root of given number.
I proceeded via a binary search approach.
int mySqrt(int x) {
if (x==0 || x==1){
return x;
...
0
votes
0
answers
33
views
What a reason for C2148 or similar errors on another compilers?
I found interesting problem, and can't find the proper answer:
The error c2148 happens, when you try to create array with 2^31 + 1 elements. Same errors I found in another compilers: Clang, GCC, etc. (...
0
votes
2
answers
157
views
What determines the data type of a variable- the declarative keyword (short int) or the format specifier (%hd)?
I have been trying to understand the integer overflow in C-programming. I am confused about whether the final value output depends on the initial datatype given to the variable during declaration or ...
1
vote
1
answer
174
views
Calculation of Cliffs delta with very large groups causes integer overflow
In R, I need to calculate Cliffs delta. Here is the formula:
Where xi is an observation in group A, and xj is an observation in group B, and [xi > xj] is 1 if xi > xj is true.
Here is Cliff's (...
2
votes
2
answers
254
views
best way to recognize and handle integer overflow in c?
I am so new in C and so far I didn't comprehend how to prevent from integer overflow, I read many articles but still I am not 100% sure!
in this case
int ft_sqrt(int nb)
{
long int sqrt;
...
1
vote
2
answers
220
views
Why negative values appear sporadically in Fibonacci Series' calculation? [duplicate]
I have coded a program which calculates Fibonacci Series in C++. Here's the code below:
#include <iostream>
using namespace std;
int main() {
int n, t1 = 0, t2 = 1, nextTerm = 0;
cout &...
2
votes
1
answer
168
views
Why does pandas sum() give wrong answers for Sparse dataframe?
In a Sparse dataframe, the sum() method applied on the whole dataframe gives wrong results, while sum() applied to specific column or to a dataframe subset works.
It looks like an overflow issue for ...
1
vote
1
answer
125
views
SQL 3.3 xmalloc overflow example - why?
The following example can be found in many places on the internet:
The following code excerpt from OpenSSH 3.3 demonstrates a classic case of integer overflow:
(bad code)
Example Language: C
nresp = ...