Re: Invalid results from exp2 function (C math library)
- From: user923005 <dcorbit@xxxxxxxxx>
- Date: Sat, 7 Jun 2008 01:12:30 -0700 (PDT)
On Jun 6, 11:30 pm, pcauchon <pcauc...@xxxxxxxxx> wrote:
On Jun 7, 3:19 pm, user923005 <dcor...@xxxxxxxxx> wrote:
On Jun 6, 11:09 pm, pcauchon <pcauc...@xxxxxxxxx> wrote:
On Jun 7, 2:52 pm, "bigcaterpil...@xxxxxxxxx"
<bigcaterpil...@xxxxxxxxx> wrote:
The value x implies exp2(x) has overflow. You can use exp(x) to try.
When I try with the standard exp function I do get normal results:
exp(-x) is always equal to 0 when x is larger than about 750.
I get the issue I described earlier only with the exp2 function.
GIGO.
Has it occurred to you that exp(-x) is not equal to zero when x is
larger than 750?
It seems strange that it should make you happy.
You are asking your floating point library to do something it isn't
able to do.
#include <math.h>
#include <stdio.h>
int main(void)
{
double dexp = exp(-750);
double dback = log(dexp);
printf("%.20g should be 750.0 but is it?\n", dback);
return 0;
}
I agree with you it's not symetric. Anyway very few floating point
operation have exact symetric inverse and that's a well-known
limitation.
In my specific case I only take exponent of negative values. I would
expect the result of exp(x) or exp2(x) for x <= 0 to be between 0 and
1. I do not really care if I have an absolute error less than say
10**-10, so computing 0 instead of the exact 10**-483 or whatever the
value is doesn't bother me.
I have problems when I get a negative result from exp2 or when the
result magnitude is larger than 1. From what I see I could get both
even if it clearly doesn't make any sense.
I worry that you are inserting values larger than -2000 into exp2() in
the first place. That is not too different from inserting -1 into
sqrt() or tan(pi/2) or any other value that is not going to be
representible because the domain does not make sense for the given
hardware. If you have values that extreme, why are you taking
negative exponentials of them?
Once intermediate calculations underflow, you should not expect
subsequent calculation to make sense.
Consider my example of exp(log(x)). Mathematically, the answer is x,
but if I insert a huge or tiny x, then the answer will no longer have
any meaning. I expect that some intermediate calculation hurled
chunks when you told it to take the exponential of something smaller
than is possible for the hardware.
Any clue on how to detect when a floating point underflow occurs?
It depends on your compiler. On some compilers you can set floating
point exceptions to have implementation defined behavior.
.
- References:
- Invalid results from exp2 function (C math library)
- From: pcauchon
- Re: Invalid results from exp2 function (C math library)
- From: bigcaterpillar@xxxxxxxxx
- Re: Invalid results from exp2 function (C math library)
- From: pcauchon
- Re: Invalid results from exp2 function (C math library)
- From: user923005
- Re: Invalid results from exp2 function (C math library)
- From: pcauchon
- Invalid results from exp2 function (C math library)
- Prev by Date: Re: pointer variable vs reference variables
- Next by Date: Re: sqrt() double trouble
- Previous by thread: Re: Invalid results from exp2 function (C math library)
- Next by thread: Re: Invalid results from exp2 function (C math library)
- Index(es):
Relevant Pages
|
Loading