Tagged Questions
0
votes
1answer
21 views
Changing equation to extend integer overflow
Problem definition
I have a 2d scenario represented by a set of points (x,y), where x and y are 64bit integers. Both x and y values are in range of [0, R] (minimum possible x value is 0 and maximum ...
2
votes
4answers
81 views
Signed integers' undefined behavior and Apple Secure Coding Guide
Apple Secure Coding Guide says the following (page 27):
Also, any bits that overflow past the length of an integer variable (whether signed or unsigned) are dropped.
However, regards to signed ...
1
vote
1answer
523 views
G++ allows for implicit long-to-int truncation on x64
I compile this code with g++ -Wall, get no warnings/errors:
#include "stdio.h"
int main() {
long x = 1000000000000;
int y = x;
printf("%ld %d\n", x, y);
return 0;
}
...
8
votes
3answers
2k views
Clojure - Calculate with big numbers
I want to calculate !1000 in clojure, how can I do this without getting a integer-overflow exception?
My factorial code is right now: (reduce * (range 1 1001)).
7
votes
5answers
763 views
Permutation with Repetition: Avoiding Overflow
Background:
Given n balls such that:
'a' balls are of colour GREEN
'b' balls are of colour BLUE
'c' balls are of colour RED
...
(of course a + b + c + ... = n)
The number of permutations in which ...
10
votes
4answers
2k views
No useful and reliable way to detect integer overflow in C/C++?
Possible Duplicate:
Best way to detect integer overflow in C/C++
No, this is not a duplicate. The issue is the same but the question is different.
The gcc compiler can optimize away an overflow ...
3
votes
2answers
743 views
What's an efficient way to avoid integer overflow converting an unsigned int to int in C++?
Is the following an efficient and problem free way to convert an unsigned int to an int in C++:
#include <limits.h>
void safeConvert(unsigned int passed)
{
int variable = static_cast<...
9
votes
3answers
41k views
Warning : overflow in implicit constant conversion
In the following program, the line 5 does give overflow warning as expected, but surprisingly the line 4 doesn't give any warning in GCC: http://www.ideone.com/U0BXn
int main()
{
int i = 256;
...
25
votes
13answers
2k views
Why would you want an integer overflow to occur?
In this question the topic is how to make VS check for an arithmetic overflow in C# and throw an Exception: C# Overflow not working?
One of the comments stated something weird and got upvoted much, I ...
18
votes
5answers
13k views
How do I detect overflow while multiplying two 2's complement integers?
I want to multiply two numbers, and detect if there was an overflow. What is the simplest way to do that?
13
votes
7answers
6k views
How do I get real integer overflows in MATLAB/Octave?
I'm working on a verification-tool for some VHDL-Code in MATLAB/Octave. Therefore I need data types which generate "real" overflows:
intmax('int32') + 1
ans = -2147483648
Later on, it would be ...
10
votes
3answers
10k views
Checking for underflow/overflow in C++?
Is there a general way to check for an overflow or an underflow of a given data type (uint32, int etc.)?
I am doing something like this:
uint32 a,b,c;
... //initialize a,b,c
if(b < c) {
a -= (...
7
votes
4answers
342 views
C++ long overflowing prematurely
I'm having a bizarre problem with C++ where the long data type is overflowing long before it should. What I'm doing (with success so far) is to have integers behave like floats, so that the range [-...
2
votes
2answers
1k views
Overflow In c
I have a doubt
When two 16 bit values are added with max values, will there be overflow in the 16 bit machines?
I will elaborate
unsigned short a;
unsigned short b;
unsigned long c;
c=(unsigned ...
7
votes
4answers
3k views
C integer overflow behaviour when assigning to larger-width integers
If I execute the following code in C:
#include <stdint.h>
uint16_t a = 4000;
uint16_t b = 8000;
int32_t c = a - b;
printf("%d", c);
It correctly prints '-4000' as the result. However, I'm ...
8
votes
10answers
6k views
Java multiply operation behavior
I wrote a method to convert a given number from days to milliseconds:
private long expireTimeInMilliseconds;
...
public void setExpireTimeInDays(int expireTimeInDays)
{
expireTimeInMilliseconds = ...
11
votes
8answers
15k views
How to handle arbitrarily large integers
I'm working on a programming language, and today I got the point where I could compile the factorial function(recursive), however due to the maximum size of an integer the largest I can get is ...