473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is double the highest precision floating point type?

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
ms*@virtualsciences.nl
Jul 21 '05 #1
8 1793
"Michel" <ms*@virtualsciences.nl> wrote in message
news:bp**********@reader11.wxs.nl...
Any suggestions anyone?

Maybe a good opportunity to try a Fortran compiler for .NET, I've found
some:
http://www.salfordsoftware.co.uk/com...5/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.

Jul 21 '05 #2
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.
"Michel" <ms*@virtualsciences.nl> wrote in message
news:bp**********@reader11.wxs.nl...
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
ms*@virtualsciences.nl

Jul 21 '05 #3
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

"Eric Gunnerson [MS]" <er****@online.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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. "Michel" <ms*@virtualsciences.nl> wrote in message
news:bp**********@reader11.wxs.nl...
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
ms*@virtualsciences.nl


Jul 21 '05 #4
"Michel" <ms*@virtualsciences.nl> wrote in message news:<bp**********@reader11.wxs.nl>...
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
ms*@virtualsciences.nl


If you look at http://groups.google.com/gr*********...ing.google.com
you'll see a discussion on how to calculate probabilities associated
with the Poisson distribution.

Ian Smith
Jul 21 '05 #5
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.
"Michel" <ms*@virtualsciences.nl> wrote in message
news:bq**********@reader11.wxs.nl...
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

"Eric Gunnerson [MS]" <er****@online.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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, appl y 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.
"Michel" <ms*@virtualsciences.nl> wrote in message
news:bp**********@reader11.wxs.nl...
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
ms*@virtualsciences.nl



Jul 21 '05 #6
Michel & Eric,
exp(-100) == exp(-10) * exp(-10)

in mathematical terms.


Nope, exp(-10) * exp(-10) == exp(-20)

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Jul 21 '05 #7
Eric Gunnerson [MS] <er****@online.microsoft.com> wrote:
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)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #8
Thanks Mattias and Jon - you are, of course, correct.

--
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.
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:uD**************@TK2MSFTNGP09.phx.gbl...
Michel & Eric,
exp(-100) == exp(-10) * exp(-10)

in mathematical terms.


Nope, exp(-10) * exp(-10) == exp(-20)

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: f | last post by:
I have this double sum, a, b, c; sum = a + b + c; printf("%.20f = %.20f, %.20f, %.20f", sum, a, b, c); I found that the debug version and release version of the same code give me different...
11
by: Christian Christmann | last post by:
Hi, just a general question. Which data type is more precise for large values: float or double? Thank you. Chris
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
8
by: Michel | last post by:
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...
10
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
67
by: lcw1964 | last post by:
This may be in the category of bush-league rudimentary, but I am quite perplexed on this and diligent Googling has not provided me with a clear straight answer--perhaps I don't know how to ask the...
116
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused...
6
by: Alexander Stoyakin | last post by:
Hello, please advise on the following issue. I need to check that difference between two double values is not higher than defined limit. int main() { double limit = 0.3; double val1 = 0.5,...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.