FAQ Database Discussion Community


Do C# and Java longs form a commutative ring?

java,c#,language-lawyer,integer-overflow
A ring is a standard mathematical structure describing objects which can be added and multiplied. Do C# and Java signed longs obey all the properties of a ring? For example, is multiplication by Long.MIN_VALUE always associative and distributive? Assume we are in an unchecked context. (definition copied from Wikipedia) A...

Doctrine2 gives me wrong sequence numbers (overflow)

symfony2,doctrine2,integer-overflow
I'm using Symfony2 and I have some entities defined with @ORM\GeneratedValue(strategy="AUTO") and @ORM\SequenceGenerator(sequenceName="mysequence_seq"). My sequences are using very big numbers: they are defined as numeric(22). The problem I have is that Symfony is fetching this values as integers, and this is wrong because this numbers doesn't fit in a single...

Checking if calculation will cause overflow c++

c++,integer-overflow
I added the elseif statement in collatz() to check if workingnumber * 3 + 1 will go over INT_MAX but when running the program some numbers which should not go over INT_MAX are reported as doing so. I might not need to cast INT_MAX but I'm not sure. #include <iostream>...

Why this loop freezes my browser?

javascript,integer-overflow
Why browser hangs executing this? for(var i= 9007199254740993;i<9007199254740994;i++) { console.log(i); } ...

Overflow of an enum type in C?

c,enums,integer-overflow
If I have an enum type, like: enum week{ sunday=0, monday, tuesday, wednesday, thursday, friday, saturday}; and I have: enum week day; day = saturday; day++; What will be the value of day?...

ASM8086: mul, imul, carry flag and overflow flag

assembly,integer-overflow,carryflag
I understood the logic of the carry flag and the overflow flag. But, when I read this program (wrote in MASM 8086) , I got perplexed a bit. The program intent is to tell if a quadratic equation has two distincts solutions, two equals solutions or no solutions at all....

How does int(or long long) overflow in c++ affect modulus?

c++,long-integer,modulus,integer-overflow
Suppose I have two long longs, a and b, that I need to multiply, then get the value mod k for some large k, such that a, b, and k are all in the range of long long but not of int. For simplicity, a, b < k. Thus the...

Visual Basic 2010 Overflow Error

vb.net,application-settings,integer-overflow
So I'm making a game with an infinitaly expandable length of numbers and I've gone to 2.1 Billion. This gives an overflow error. Arithmetic operation resulted in an overflow. In my code I have these two variables: Dim coal As BigInteger Dim totalCoal As BigInteger And these two app settings...

Do numerical programming languages distinguish between a “largest finite number” and “infinity”?

python,matlab,numpy,integer-overflow
Question motivation: In standard numerical languages of which I am aware (e.g. Matlab, Python numpy, etc.), if, for example, you take the exponential of a modestly large number, the output is infinity as the result of numerical overflow. If this is multiplied by 0, you get NaN. Separately, these steps...

Integer division overflows

c++,c,cross-platform,standards,integer-overflow
The Problem I have been thinking about integer (type int) overflows, and it occurs to me that division could overflow. Example: On my current platform, I have INT_MIN == -INT_MAX - 1 and thus INT_MIN < -INT_MAX and thus INT_MIN / -1 > -INT_MAX / -1 and thus INT_MIN /...

Arithmetic operation resulted in an overflow Error

vb.net,memory,byte,integer-overflow
I am getting this error Arithmetic operation resulted in an overflow I have already looked it up on stackoverflow. still couldn't find a solution. My code Private m_MemReg As List(Of MEMORY_BASIC_INFORMATION) Public Sub MemInfo(ByVal pHandle As IntPtr) Dim Addy As New IntPtr() While True Dim MemInfo As New MEMORY_BASIC_INFORMATION() Dim...

Unexpected result when calculating a percentage - even when factoring in integer division rules

c,percentage,integer-overflow,integer-division
I am trying to express a battery voltage as a percentage. My battery level is a (global) uint16 in mV. I have a 16-bit CPU. Here is my code: static uint8 convertBattery(void){ uint16 const fullBattery = 3000; /* 3V = 3000mV */ uint8 charge; charge = ((battery*100)/fullBattery); return charge; }...