Is double the highest precision floating point type?

  • Thread starter Thread starter Michel
  • Start date Start date
M

Michel

Hi there,

I need to make a poisson distribution function that uses:

double Math.Exp(double d)

The d argument is a negative number in my case. When d becomes bigger and
bigger, the result loses precision and is finally 0 (when d reaches 650)
because it is too small to fit in a double. In my case, d can become -10000,
so I need to have a greater precision number and Exp function.

I've looked at decimal, but it cannot contain as small a number as double
(just try to put a small double in a decimal and the decimal will be 0).
Furthermore, there is no Math.Exp overload that takes decimals.

Any suggestions anyone?
Thanks,
Michel
(e-mail address removed)
 
Michel said:
Any suggestions anyone?
Maybe a good opportunity to try a Fortran compiler for .NET, I've found
some:
http://www.salfordsoftware.co.uk/compilers/ftn95/dotnet.shtml
http://www.lahey.com/lf70/lfnet.htm
These compilers will probably handle numeric types with a higher precision
or provide a better implementation of Math functions. You can write a
component in Fortran.NET that does the job but you must remember that the
interface with this component must only use CLS compliant types,
System.Double or System.Decimal in your case.
 
Given the size of the value you're passing, I don't think there's any type
that would work well. I can think of a few things to try:

1) Find a library that supports larger exponents. There may be some on this
page - http://www.oonumerics.org/oon/ - but my guess is that you won't find
a C# one. You might be able to find a free Java one and either
hand-translate or run the Java Language Conversion Assistant on it (assuming
the license allows that).
2) Modify your calculation so that you don't need to compute the entire
value all at once. If, for example, you are going to multiply this by
something that is pretty big, you can factor apart the calculation, apply
Math.Exp(-10) 4 times to get the equivalent of Math.Exp(-10000)

Hope that helps.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Eric,

I'd like to try breaking the calculation up.
How do I get from Math.Exp(-10) back to Math.Exp(-10000)?
I've done some testing....
Math.Exp(-4) = Math.Exp(-2) * Math.Exp(-2)

However, this doesn't apply to e.g. 100:
Math.Exp(-100) != Math.Exp(-10) * Math.Exp(-10).

Also, my input is not as "nice" as 10000, it'll be more like 1234,56.

Thanks,
Michel
 
Michel said:
Hi there,

I need to make a poisson distribution function that uses:

double Math.Exp(double d)

The d argument is a negative number in my case. When d becomes bigger and
bigger, the result loses precision and is finally 0 (when d reaches 650)
because it is too small to fit in a double. In my case, d can become -10000,
so I need to have a greater precision number and Exp function.

I've looked at decimal, but it cannot contain as small a number as double
(just try to put a small double in a decimal and the decimal will be 0).
Furthermore, there is no Math.Exp overload that takes decimals.

Any suggestions anyone?
Thanks,
Michel
(e-mail address removed)

If you look at http://groups.google.com/[email protected]
you'll see a discussion on how to calculate probabilities associated
with the Poisson distribution.

Ian Smith
 
Michel,

exp(-100) == exp(-10) * exp(-10)

in mathematical terms. It's not equal in the computer, however, because the
floating-point representation is inexact.

I'm assuming that you would multiplying this the result of exp(-10000) by a
large positive number. If not, then your result might be outside the range
of double anyway.

I hope that helps. If you have more questions, please give us some more
information on what you're trying to do and what algorithm you're using.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Eric Gunnerson said:
exp(-100) == exp(-10) * exp(-10)

in mathematical terms.

No it doesn't. exp (-10) * exp(-10) = exp (-20)

Forget e here, let's take an example which is easier to work with: 3

3^2 * 3^3 = 9*27 = 243
3^(2*3) = 3^6 = 729
3^(2+3) = 3^5 = 243

In general, x^y * x^z = x^(y+z), not x^(y*z)
 
Back
Top