
Int possible_10_exponent= (exponent - exponent_adjustment)/3

Luckily, 5^22 also only has 52 significant bits, so we can determine if a double is (2*5)^n for n= : bool is_pow10(double value)ĭouble mantissa= frexp(value, &exponent) Note that the comparison to 0.0 is exact rather than within a particular epsilon since you want to ensure that log10_value is an integer.ĮDIT: Since this sparked a bit of controversy due to log10 possibly being imprecise and the generic understanding that you shouldn't compare doubles without an epsilon, here's a more precise way of determining if a double is a power of 10 using only properties of powers of 10 and IEEE 754 doubles.įirst, a clarification: a double can represent up to 1E22, as 1e22 has only 52 significant bits. There are mathematical libraries available with BigInt implementations or you can roll your own (though efficiency is difficult to achieve).Ī variant of this one: double log10_value= log10(value) ĭouble fractional_value= modf(log10_value, &integer_value) If you really need this precision, my suggestion is not to use a floating point number. you can't test it for being a power of ten. So normally you should be able to represent integers from 0 to 10 14 faithfully.įinally some platforms may have a long long type with an ever greater precision.īut anyway, as soon as your value exceed the number of digits available to be converted back to an integer without loss. You can of course use a much more precise representation, like double which has 15 digits of precision. So if you represent 10 9 as a float chances are it will be converted back as 1 000 000 145 or something like that: nothing guarantees what the last digits will be, they are off the precision. There is no way to cast down a very large or very small floating point number to a BigInt class because you lost precision when using the small floating point number.įor example float only has 6 digits of precision. *in American English, 1 x 10 12 = one thousand million in British English.Įxamples of simple math using scientific notation AdditionI am afraid you're in for a world of hurt. Examples of Scientific Notation, Metric Prefixes, and Symbols Word Using a pocket calculator with an exponent key, usually labeled EX or EE or EX, the number: 4.3 x 10 5 is entered as 4.3 EX 5. Here are some alternate forms of notation for the same numerical values: 3.2 x 10 8 Note that the negative sign in the exponent means the value is less than one. For example, the size of an atom is on the order (or about) a few Ångströms (Å) which is defined as: Not only can one use scientific notation to express large numbers but also very small numbers. Note that 2.0 is the coefficient and 30 is the exponent. For example, the distance from the Earth to the Sun is referred to as the Astronomical Unit (AU) and is: 1 AUĪnother dimension to illustrate this kind of notation is the mass of the Sun expressed in units of kilograms (kg): Mass of the Sun Consequently, scientific notation has been introduced to deal with such quantities.

Microscopy is the subject of very small numbers. Scientific Notation:Īstronomy is the subject of very large numbers. Thus we can now proudly state that 1 nm = 10 -3 m. For example, milli- always means one thousandth. They multiply the unit by some power of 10. There is a method to the prefixes centi-, milli-, etc. (This is a convenient unit for high-power microscopes, with which one can look at objects as small as a few micrometers. (This unit is often used because a typical atom is a few Ångströms in size.) The wavelength of yellow light in a vacuum may be called 5750 Å or 575 mµ or 575 nm or 0.575 µm. Unfortunately, many different names are used. This much is fine for everyday lengths, but for light we have to use even smaller units of length because its wavelength is so small. It is easier to use the metric system where everything goes by powers of 10: 1 meterġ0 -3 m ~ 1/25 inch (width of lead in pencil) That gets messy if we want to convert from miles to inches. But there are 12 inches in a foot, 5280 feet in a mile and so on. For people's heights we use feet and inches.

No one gives the distance between cities in inches we use miles. People find it cumbersome to speak of units of measurement like "one ten thousandth of a billionth" of an inch, or even "ten to the minus thirteenth" (10-13) inches so they devise different names. Basic Math, Scientific Notation and Astronomical Dimensions Dealing with Numbers Great and Small
