Large floating point numbers

  • Thread starter Thread starter Pete Davis
  • Start date Start date
P

Pete Davis

I'm interested in writing some chem/biochem related tools for myself, but it
appears the Decimal format isn't going to quite cut it for some of the
numbers I'm going to be working with. It's max of ~10^28 is a bit shy of the
at least 10^34 precision I know I'll need at the very least.

Actually, I don't need all the precision. I simply need to be able to have
numbers that go that high. If the actual precision is only to 15 or 20 or so
digits, that would be plenty.

Anyway, are there any libraries for .NET that support large decimal numbers?
I know the gmp library does, but it's C and it looks like it's a nightmare
to build under Linux so I imagine it's only harder to build under Windows.

Thanks.

Pete
 
I'm not aware of any custom libraries to handle larger numbers, but
then again - I've never really needed to find one ^_^

Here are your two built in data types that would be the most likely,
but neither can do 10^34.

decimal
Appx Range: ±1.0 × 10e-28 to ±7.9 × 10e28
Precision: 28-29 significant digits
.Net Framework Type: System.Decimal

double
Appx Range: ±5.0 × 10-324 to ±1.7 × 10308
Precision: 15-16 digits
.Net Framework Type: System.Double
 
You can get a pre-compiled GMP library (DLL) that works under windows (and
can be got at via DllImport directives) at
http://www.cs.nyu.edu/exact/core/gmp/ , so you do not have to build GMP for
windows.

I have used it with good results in one of my applications. I creating a
tiny VS 2005 managed C++ library project that just wraps GMP calls in C#
classes, and have used the resulting DLL in a few C# projects without a
problem.

If you are interested, I can zip up the VS 2005 C++ project source and email
it to you. I only wrote interfaces for the GMP (integer) functions I
needed, but you can easily follow the pattern to access the GMP floating
point functions. You will need the documentation for GMP at
http://www.swox.com/gmp/#DOC to write the interface functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top