Skip to main content
Filter by
Sorted by
Tagged with
3 votes
2 answers
155 views

I am writing a function that takes a string, converts it to an integer and returns the remainder of that value divided by 4. For the purposes of this function, I have to make it able to process very ...
Caio Becker Porto Fransozi's user avatar
Best practices
1 vote
7 replies
133 views

I'm trying to find a best-practice method to handle an edge case when a hardware clock timer wraps around and the overflown value generates a false positive logic match. For example, on a 16 MHz chip, ...
zero-day's user avatar
  • 402
13 votes
3 answers
3k views

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 ...
Daniil Zuev's user avatar
Advice
1 vote
5 replies
108 views

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 + ...
Martin Modrák's user avatar
0 votes
0 answers
102 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
  • 140
5 votes
2 answers
185 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
206 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
116 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
372 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
436 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,237
1 vote
1 answer
71 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
  • 21
0 votes
1 answer
79 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
200 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.8k
2 votes
3 answers
124 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
63 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
144 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,366
0 votes
5 answers
182 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
146 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: ...
genicki's user avatar
  • 83
21 votes
2 answers
302 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
111 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
  • 159k
1 vote
1 answer
194 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
210 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
628 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
198 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
238 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
539 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,023
5 votes
1 answer
104 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
106 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
242 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
94 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,505
2 votes
1 answer
117 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
94 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,422
0 votes
1 answer
155 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
56 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
629 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
641 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
65 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
290 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
52 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
165 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
172 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
204 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
  • 191
0 votes
1 answer
188 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
270 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
205 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
268 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
269 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
171 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

1
2 3 4 5
23