# Thread: Under/Overflow you do handle them

1. ## Under/Overflow you do handle them

I have a function that gives me log(y) and derivative of log(y) call it dlog(y) . However I am interested in knowing y and derivative of y call it dy. Now I get dy as follows
Code:
```dy = exp( log (y)) * dlog ( y)
which is equaivalent to

dy = exp( log (y)) * (1/ y * dy)

which simplifies to

dy = dy```
I get under/overflow problems when y is close to zero. Any suggestions?

2. Floating point numbers are notoriously inaccurate. You cannot expect to get every number from .0000000001 (or whatever small number) up to 1 successfully stored in 32 bits. (Or whatever bit representation you want.) At best you can approximate it, and that's what floating point numbers do. There are huge write ups on the topic, but I've never found them interesting enough to read. If you really want to know: Single precision floating-point format - Wikipedia, the free encyclopedia

At least I'm going to assume that is what your question is about.

Quzah.

3. I'd be interested in knowing how you know you're getting overflow and underflow... since C includes no runtime error trapping.

4. Because in another part of the code when I switched from exp to expl it got rid of some problems. I am guessing it is an over/underflow problem because for a sequence of numbers that get closer to zero, I start getting rubbish answers.

5. You should really read this.
What Every Computer Scientist Should Know About Floating-Point Arithmetic
In particular, everything where relative error is discussed.

If you're doing serious floating point work, you need to be able to analyse where these kinds of errors are introduced, and how to write the code in such a way as to minimise the effects. As the paper discusses, x^2 - y^2 is mathematically identical to (x - y)(x + y), but on a machine with a finite number of bits, there are some surprises waiting. In short, you can't simply copy/paste your maths directly into 'C' code and hope that it will all work out.

Because statements like "when I switched from exp to expl it got rid of some problems" mean you're just stumbling around in the dark walking into things.

6. Originally Posted by ali.franco95
Because in another part of the code when I switched from exp to expl it got rid of some problems. I am guessing it is an over/underflow problem because for a sequence of numbers that get closer to zero, I start getting rubbish answers.
Most likely you are running into the well known inaccuracies of floating point math...

In post #5 Salem provides a link to an excellent discussion of the problem... It's the red text, click and read...