integer-overflow Questions
8
Solved
In this article: http://googleresearch.blogspot.sg/2006/06/extra-extra-read-all-about-it-nearly.html, it mentioned most quick sort algorithm had a bug (left+right)/2, and it pointed out that the so...
Abbieabbot asked 27/11, 2014 at 10:9
1
Solved
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-&...
Katricekatrina asked 12/6, 2024 at 11:5
3
Solved
I am writing a cycle method for a list that moves an index either forwards or backwards. The following code is used to cycle backwards:
(i-1)%list_length
In this case, i is of the type usize, me...
Saintsimonianism asked 23/12, 2016 at 12:24
8
Solved
Unsigned integer overflow is well defined by both the C and C++ standards. For example, the C99 standard (§6.2.5/9) states
A computation involving unsigned operands can never overflow,
because ...
Ledger asked 12/8, 2013 at 20:4
16
Solved
I am looking for an efficient (optionally standard, elegant and easy to implement) solution to multiply relatively large numbers, and store the result into one or several integers :
Let say I have...
Bautista asked 29/11, 2009 at 12:14
10
Solved
In several modern programming languages (including C++, Java, and C#), the language allows integer overflow to occur at runtime without raising any kind of error condition.
For example, consider t...
Gemmule asked 19/9, 2008 at 16:53
3
Solved
If a C program has undefined behavior, anything can happen. Therefore compilers may assume that any given program does not contain UB. So, suppose our program contains the following:
x += 5;
/* Do ...
Scuppernong asked 18/9, 2023 at 22:45
5
Solved
This is a complete rewrite of the question. Hopefully it is clearer now.
I want to implement in C a function that performs addition of signed ints with wrapping in case of overflow.
I want to tar...
Firecracker asked 12/12, 2019 at 15:27
2
Solved
I am doing a bunch of applied-mathematics/signal-processing/algorithms C++ code.
I have enabled the -Wconversion compiler warning to catch issues like runtime conversion of numbers that are type do...
Cavafy asked 4/4, 2018 at 18:40
2
Solved
I was unit testing in C#, and I found the following code gives an overflow exception:
using System;
public class Program
{
public static void Main()
{
int i = 0;
Console.WriteLine(new float[i...
Gurango asked 2/6, 2023 at 9:22
3
Solved
For most operators that might overflow, Rust provides a checked version. For example, to test if an addition overflows one could use checked_add:
match 255u8.checked_add(1) {
Some(_) => println...
Norway asked 22/8, 2020 at 15:3
5
Solved
I have got two signed integers, and I would like to subtract them. I need to know if it overflowed.
int one;
int two;
int result = two - one;
if (OVERFLOW) {
printf("overflow");
} else ...
Deledda asked 27/10, 2009 at 20:48
2
Solved
fn main() {
let num: u8 = 255;
let num2: u8 = num + 1;
println!("{}, {}", num, num2);
}
When $ cargo build --release, this code doesn't make compile error.
And $ cargo run, make runt...
Danais asked 5/4, 2023 at 12:25
4
Why is there a runtime error? I made range2 a long long.
Code:
/*VARIABLES FOR WHILE LOOP*/
long long range1 = 9;
int length = 1;
/*FIND NUM'S LENGTH*/
while (NUM > range1)
{
long long...
Convey asked 6/12, 2016 at 3:2
3
Solved
I was wondering on how to use this function, because I get an error when I do this:
#define INT_ADD_OVERFLOW_P(a, b) \
__builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0);
#include <std...
Pettus asked 28/7, 2016 at 1:46
6
Solved
I had this weird experience with problem number 10 on Project Euler (great site by the way). The assignment was to calculate the sum of all the prime numbers below two million.
I used an int for t...
Stereotype asked 13/1, 2010 at 12:9
4
Solved
I have an int x. For simplicity, say ints occupy the range -2^31 to 2^31-1. I want to compute 2*x-1. I allow x to be any value 0 <= x <= 2^30. If I compute 2*(2^30), I get 2^31, which is an i...
Ryals asked 17/10, 2022 at 20:5
9
Solved
I often see questions relating to Overflow errors with vba.
My question is why use the integer variable declaration instead of just defining all numerical variables (excluding double etc.) as long...
Lutenist asked 16/10, 2014 at 16:11
11
Solved
I am trying to write a C++ template function that will throw a runtime exception on integer overflow in casts between different integral types, with different widths, and possible signed/unsigned m...
Lawrence asked 15/6, 2009 at 21:48
1
Solved
(I'm an novice, so there may be inaccuracies in what I say)
In my current mental model, an overflow is an arithmetical phenomenon (occurs when we perform arithmetic operations), and an implicit con...
Tye asked 24/7, 2022 at 20:50
1
For once I thought I found a good use for sscanf() but after reading about how it handles integers, it appears not. Having a string that should look like this: 123,456,678 I thought I could safely ...
Agneta asked 24/2, 2021 at 0:40
6
Solved
Generally, How can I prevent integer overflow from happening in C programming language? I mean, Is there any functions to prevent?
And finally, Is integer overflow going to get me hacked like buffe...
Renelle asked 16/7, 2020 at 13:25
3
Solved
Per the specification of strtol:
If the subject sequence has the expected form and the value of base is 0, the sequence of characters starting with the first digit shall be interpreted as an integ...
Oversubtle asked 8/6, 2013 at 19:54
2
Modular inverses can be computed as follows (from Rosetta Code):
#include <stdio.h>
int mul_inv(int a, int b)
{
int b0 = b, t, q;
int x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a >...
Ebonee asked 30/11, 2018 at 15:22
3
I need to convert one kind of std::chrono::duration to another kind but I need to know when such a conversion is not possible because the value would not be representable.
I have not found any fac...
Forester asked 19/6, 2017 at 16:48
1 Next >
© 2022 - 2025 — McMap. All rights reserved.