Reputation: 3854
I have values greater than 1.97626258336499E-323
I cant use BigInteger also as it handler only integer values
Any help is appreciated
Here is the code that failed also failed with some solution given by some users:
BigValue / (Math.Pow((1 + ret), j));
WHere BigValue is something like 15000.25
ret is -0.99197104212554987
And j will go to around 500-600.
I am not gettting how to use Rational Class for this too
Upvotes: 6
Views: 2599
Reputation: 9
Here is something that may be useful. I used it a while back with no problem. It is a .Net BigDecimal class, you can download it from codeplex(or just look at the source):
http://bigdecimal.codeplex.com/releases/view/44790
It is written in VB.Net (.Net 4.0), but that shouldn't matter.
An example of its use in C#: http://www.dreamincode.net/forums/blog/217/entry-2522-the-madman-scribblings/
Upvotes: 1
Reputation:
Learn how to use logs to work with numbers like these. Yes, you CAN use a big float package, but that is overkill almost always. You can usually get what you need using logs.
Upvotes: 0
Reputation: 17127
One solution might be to do your problems in log space instead.
your example would become:
exp(log(Number) - log(1-0.9999999) * 400)
Upvotes: 0
Reputation: 30695
BigRational from the base class library team from Microsoft. It uses big integers to store it as a fraction, but supports all kinds of operators.
When it comes to printing it as a decimal, I think you need to write your own implementation for that. I have one written somewhere for this class, but I'd have to find it.
Upvotes: 1
Reputation: 46960
You will have to switch languages to one that has a BigFloat
type (e.g. Haskel and Python have native packages) or else find a third party big float library with a C#
binding. There was some discussion of such a binding for GNU MP, but it faded away. Maybe you'll write one!
See also this discussion where MS BigRational is discussed. However this is different from BigFloat.
Upvotes: 0