Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >
Filter by
Sorted by
Tagged with
0 votes
0 answers
89 views

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 ...
nonhuman's user avatar
  • 141
5 votes
2 answers
177 views

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 (...
Jatin Sanghvi's user avatar
4 votes
2 answers
182 views

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 ...
jwd's user avatar
  • 11.4k
4 votes
2 answers
105 views

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 ...
red_trumpet's user avatar
6 votes
4 answers
355 views

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 ...
Joseph's user avatar
  • 61
3 votes
4 answers
328 views

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 ...
cards's user avatar
  • 5,281
1 vote
1 answer
61 views

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?...
Gad11ng's user avatar
  • 43
0 votes
1 answer
67 views

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 ...
ULF21's user avatar
  • 1
4 votes
3 answers
187 views

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; ...
Nan Xiao's user avatar
  • 17.7k
2 votes
3 answers
117 views

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 ...
Ning's user avatar
  • 23
0 votes
0 answers
404 views

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 ...
Ilario Bisignano's user avatar
0 votes
0 answers
60 views

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 ...
M0M0's user avatar
  • 236
-3 votes
2 answers
111 views

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 ...
khteh's user avatar
  • 4,280
0 votes
5 answers
171 views

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? ...
Shiva kumar das's user avatar
0 votes
1 answer
131 views

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: ...
gnicki's user avatar
  • 83
21 votes
2 answers
275 views

Signed int arithmetic operations can overflow and underflow, and when that happens, that is undefined behavior as per the C++ standard (and C standard). At which point the program can be expected to ...
Always Becurious's user avatar
1 vote
2 answers
106 views

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 ...
Brendan Langfield's user avatar
11 votes
2 answers
1k views

Is multiplication order important when allocating? Even if multiplication may affect things in general, what about common ordering concerns with allocation sizing? data = malloc(row * col * sizeof ...
chux's user avatar
  • 158k
1 vote
1 answer
160 views

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 ...
Pranav's user avatar
  • 13
2 votes
2 answers
198 views

I'm trying to write a short code that calculates the Hamming weight of integers: class Solution { public: int hammingWeight(int n) { if(n==0){ return 0; }else{ ...
simply lemon's user avatar
2 votes
1 answer
471 views

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 ...
Olivier Lasne's user avatar
4 votes
2 answers
185 views

I need to compute recursively an integer number represented by an unsigned int down a tree. Each node is associated with an integer value calculated recursively by multiplying the numbers of its ...
Arnaud's user avatar
  • 223
0 votes
0 answers
214 views

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 ...
SamuelMastrelli's user avatar
0 votes
1 answer
413 views

I'm reading a textbook on systems programming and it states that an overflow occurs for unsigned integers if and only if the carry-in bit is mismatched with the carry-out, in the left-most bit. So if ...
Addem's user avatar
  • 4,013
5 votes
1 answer
102 views

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()...
Alan Shiah's user avatar
  • 1,086
0 votes
1 answer
94 views

The following integer overflow detection function is given in Computer Systems: A Programmer's Perspective, 3e. /* Determine whether arguments can be added without overflow */ int tadd_ok(int x, int y)...
user avatar
-1 votes
1 answer
172 views

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 ...
Rust Coder's user avatar
1 vote
1 answer
87 views

<script> function hs(e, n) { return e * n % e; } alert(hs(1752865668, 1716717484170)); //result: 1752622684 </script> <?php function hs($e, $n) { return $e * $n % $e; } echo ...
Alo's user avatar
  • 1,315
2 votes
1 answer
99 views

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; ...
programk5er's user avatar
1 vote
1 answer
64 views

While going through and re-factoring some Java code I wrote a while back for Project-Euler. I ran into an issue with integer overflow where the answer was too large to contain in type int. This was ...
tijko's user avatar
  • 8,402
0 votes
1 answer
112 views

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, ...
Semnodime's user avatar
  • 2,035
0 votes
1 answer
42 views

I animate 2d point moving in excel chart by a very simple cycle: do while true .ChartObjects(1).Chart.SeriesCollection(1).XValues = x .ChartObjects(1).Chart.SeriesCollection(1).Values = y ...
Jiří Macur's user avatar
0 votes
1 answer
560 views

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-...
Venkat Balachandra's user avatar
0 votes
2 answers
549 views

I have a list of data called data. This list contains 21073 nested numpy arrays. Each numpy array, in turn, contains 512 values. Paradigmatially, one nested numpy array looks as follows: [534.42623424,...
Philipp's user avatar
  • 415
1 vote
1 answer
62 views

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; ...
Yogesh Yadav's user avatar
1 vote
1 answer
246 views

using this algorithm to calculate a multiplication of signed integers (we cant use mul, mulh etc so I implemented the mul with shift and add) how can you check if the result has overflown. The ...
gabibbo quinto's user avatar
0 votes
0 answers
29 views

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. (...
Andrew Buryakov's user avatar
3 votes
1 answer
142 views

I am a beginner in C and mess with its quirks. Why does this code even work? #include <stdio.h> int main() { unsigned char i = 126; i = (i << 1000000000000000000000000000000000) % ...
Programmer_2147483647's user avatar
0 votes
2 answers
156 views

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 ...
Abhijeet Gautam's user avatar
1 vote
2 answers
4k views

I need to make a few safe widening integer conversions – uint32 to uint and uint to uint64, for example. I know it’s possible to achieve this with an explicit type conversion: x := uint32(1) // ...
Ry-'s user avatar
  • 226k
1 vote
1 answer
167 views

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 (...
EmilA's user avatar
  • 179
0 votes
1 answer
182 views

I have written my own 2D Convolution function as follows def TwoD_convolution(img, kernel): # Flipping the kernel by 180 degrees kernel = kernel[::-1] for i in range(len(kernel)): ...
Sudheera Y S's user avatar
2 votes
2 answers
254 views

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; ...
Negar Nasiri's user avatar
1 vote
2 answers
178 views

I am looking for a signed integer comparison function cmp(x: Int, y: Int) -> Int which does not use any comparison operators (<, <=, >, >=, <=>, etc.), does not use widening to a ...
tomdodd4598's user avatar
1 vote
2 answers
220 views

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 &...
Swapon Das's user avatar
0 votes
4 answers
245 views

Given this simple code snippet: #include <stdio.h> #include <stdint.h> int main() { int8_t a = -1; printf("Dec: %d, Hex: %hhx\n", a, a); int8_t b = a + 1; printf(...
Der Fänger im Roggen's user avatar
2 votes
1 answer
167 views

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 ...
Dudelstein's user avatar
2 votes
1 answer
240 views

Is This Safe? Suppose I wanted to call some Rust code from within Python. Suppose my lib.rs looks something like this: #[no_mangle] pub extern fn add(left: i32, right: i32) -> i32 { return left+...
Tom Hosker's user avatar
1 vote
1 answer
121 views

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 = ...
HangingParens's user avatar
0 votes
1 answer
1k views

Following this thread nanoseconds-run-into-an-overflow, it was my intention to transit from nanoseconds and seconds freely but without losing any information (given the fact that nanoseconds is 64 ...
linuxbeginner's user avatar

1
2 3 4 5
23