Questions tagged [underflow]

An arithmetic underflow is a condition in a computer program where the result of a calculation is a number of smaller absolute value than the computer can actually represent in memory.

In computing, buffer underrun or buffer underflow is a state occurring when a buffer used to communicate between two devices or processes is fed with data at a lower speed than the data is being read from it. This requires the program or device reading from the buffer to pause its processing while the buffer refills.

From Wikipedia

148 questions
30
votes
7 answers

Efficient way to compute geometric mean of many numbers

I need to compute the geometric mean of a large set of numbers, whose values are not a priori limited. The naive way would be double geometric_mean(std::vector const&data) // failure { auto product = 1.0; for(auto x:data) product *= x; …
Walter
  • 44,150
  • 20
  • 113
  • 196
28
votes
3 answers

Does Javascript handle integer overflow and underflow? If yes, how?

We know that Java does not handle underflows and overflows, but how does Javascript handle these for integers? Does it go back to a minimum/maximum? If yes, which minimum/maximum? I need to split a string and compute a hash value based on its…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
23
votes
3 answers

Question about C behaviour for unsigned integer underflow

I have read in many places that unsigned integer overflow is well-defined in C unlike the signed counterpart. Is underflow the same? For example: unsigned int x = -1; // Does x == UINT_MAX? Thanks. I can't recall where, but i read somewhere that…
snap
  • 711
  • 3
  • 11
  • 25
22
votes
3 answers

C: What is a/example of a buffer underflow?

I know what a buffer overflow is. I have no idea however what a buffer underflow is. I am guessing it is when a specific buffer receives instead of an overflow of bytes, an underflow of bytes. char buffer[8]; fgets(buffer, sizeof(buffer),…
basickarl
  • 37,187
  • 64
  • 214
  • 335
20
votes
4 answers

Dealing with very small numbers in R

I need to calculate a list of very small numbers such as (0.1)^1000, 0.2^(1200), and then normalize them so they will sum up to one i.e. a1 = 0.1^1000, a2 = 0.2^1200 And I want to calculate a1' = a1/(a1+a2), a2'=a2(a1+a2). I'm running into…
dan12345
  • 1,594
  • 4
  • 20
  • 30
16
votes
2 answers

When does underflow occur?

I get into a situation where calculating 1.77e-308/10 triggers an underflow exception, but calculating 1.777e-308/10 does not. This is strange because: Underflow occurs when the true result of a floating point operation is smaller in magnitude…
zell
  • 9,830
  • 10
  • 62
  • 115
14
votes
2 answers

How to calculate sums in log-space without underflow?

I am trying to calculate log(a + b) given log(a) and log(b). The problem is, log(a) and log(b) are so negative that when I try to calculate a and b themselves, they underflow and I get log(0), which is undefined. For log(a * b) and log(a / b), this…
14
votes
5 answers

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 -= (c - b) } When I print a after some iterations, it…
Legend
  • 113,822
  • 119
  • 272
  • 400
13
votes
4 answers

Common underflow and overflow exceptions

I am trying to get a hold of overflow and underflow exceptions in java, but couldn't get any nice tutorial. Specifically I wish to learn How are they different from each other? What are the subclasses of these exceptions? In which scenario they…
Ravi Gupta
  • 4,468
  • 12
  • 54
  • 85
11
votes
6 answers

How to avoid reference count underflow in _NSCFURLProtocolBridge in custom NSURLProtocol in GC environment

The basics are I have a custom NSURLProtocol. In startLoading, [self client] is of type: <_NSCFURLProtocolBridge> {NSURLProtocol, CFURLProtocol} The problem is running this in a garbage-collected environment. Because I'm writing a screensaver,…
9
votes
3 answers

How to judge an overflow when adding signed to unsigned

I'm trying to detect the overflow when adding a signed offset to an unsigned position uint32 position; int32 offset; // it could be negative uint32 position = position+offset; How can I check whether the result is overflow or underflow? I have…
rogerz
  • 1,073
  • 9
  • 18
9
votes
2 answers

Exponential of very small number in python

I am trying to calculate the exponential of -1200 in python (it's an example, I don't need -1200 in particular but a collection of numbers that are around -1200). >>> math.exp(-1200) 0.0 It is giving me an underflow; How may I go around this…
Pi_
  • 2,010
  • 5
  • 22
  • 24
8
votes
2 answers

Handling very very small numbers in Python

I need to multiply about 1e6 numbers that are of the order of 0.01. The expected result is of order 1e-100000000. Obviously the typical floating-point arithmetic cannot handle this. Doing some research on the web I found the decimal library which…
user171780
  • 2,243
  • 1
  • 20
  • 43
8
votes
2 answers

Flush-to-zero in gfortran

Is there a way to force flush-to-zero of underflows in gfortran? I can't believe this is the first time someone has asked this, but I couldn't find anything on it anywhere. Mea culpa if this is a duplicate.
bob.sacamento
  • 6,283
  • 10
  • 56
  • 115
7
votes
4 answers

Logsoftmax stability

I know how to make softmax stable by adding to element -max _i x_i. This avoids overflow and underflow. Now, taking log of this can cause underflow. log softmax(x) can evaluate to zero, leading to -infinity. I am not sure how to fix it. I know this…
Abhishek Bhatia
  • 9,404
  • 26
  • 87
  • 142
1
2 3
9 10