Extreme math variables

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I'm making a physics that uses very small numbers such as 9.88E-19. that is,
9.88 times 10 to the power of -19. I've run into a few problems doing
calculations with numbers like these.
the first one is that I can't figure out how to write scientific notation
which is that E that I used in the first sentence. it means to multiply by
ten to some power. I know the math.E exists but I don't know how to use it.

Maybe after I figure that first part out, I will fix my other problem
because I enter numbers in like so: 0.00000000000098. and I think the
computer records the 0.0 and that's all. instead of recording 9.8 and the
number of 0's. but the problem is that I can't use the data types double or
decimal because the compiler won't let me multiply them, which makes them
useless, and I end up losing the most important digits in these
calculations. So, is there any standard way of doing such large
calculations? Are there variables I can use like decimal and still be able
to multiply?
thanks
dave
 
The "double" type should handle that scale easily.

double a = 0.00000000000098;
double b = 0.00000000000076;
double c = a * b;

This results in c=7.448E-25. What types of errors are you encountering?

Math.E is just a constant, 2.718281828459045.... It's not directly related
to the "E" in scientific notation.
 
Sounds to me like the Decimal type would be appropriate for you. Here's an
excerpt from the documentation:

The binary representation of an instance of Decimal consists of a 1-bit
sign, a 96-bit integer number, and a scaling factor used to divide the
96-bit integer and specify what portion of it is a decimal fraction. The
scaling factor is implicitly the number 10, raised to an exponent ranging
from 0 to 28.

Therefore, the binary representation of a Decimal value is of the form,
((-296 to 2 96)/ 10 (0 to 28)), where -2 96 is equal to MinValue, and 296 is
equal to MaxValue.

Tom Clement,

Apptero, Inc.
 
Dave,

You should be able to write constants like this:

double val = 9.88e-19;

We can probably help you better if you post some code and explain what
you're trying to do.

--
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.
 
Back
Top