Return mantissa=pow(5.0, possible_10_exponent) Mantissa*= pow(2.0, exponent - possible_10_exponent) 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) To convert a regular number to scientific notation, we first rewrite it as a decimal, then multiply it by a power of. 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. We also do that in reverse making larger numbers into scientific notation. 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. This tutorial shows how positive powers of 10 make numbers larger by shifting the decimal to the right. Powers of ten simplify comparison of numbers by order of magnitude.I am afraid you're in for a world of hurt.Scientific notation uses powers of ten to represent large and small quantities in a more efficient way.Dividing by a power of ten moves the decimal place to the left the same number of spaces as the exponent on the power of ten.Multiplying by a power of ten moves the decimal place to the right the same number of spaces as the exponent on the power of ten.Knowledge of the base ten number system and the result in this system when working with powers of ten is an advantage, but to complete the exercise all one needs is an ability to perform basic arithmetic operations. Multiply or divide the numbers by the power of ten The user is asked to provide all correct answers. Multiply or divide the numbers by the power of ten: This problem provides a power of ten that is to be multiplied or divide against different numbers.Multiply or divide the number by powers of ten The user is asked to fill in the correct answers. Multiply or divide the number by powers of ten: This problem asks several questions that involve multiplying or dividing a particular number that may involve decimals by different powers of ten.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. There are two types of problems in this exercise: Power of Ten Basic Math, Scientific Notation and Astronomical Dimensions Dealing with Numbers Great and Small. This exercise strengthens the knowledge that multiplying and dividing by powers of ten moves the decimal point either left or right. There are mathematical libraries available with BigInt implementations or you can roll your own (though efficiency is difficult to achieve). The Multiplying and dividing decimals by powers of 10 exercise appears under the 5th grade (U.S.) Math Mission. Yacoby A power of ten is a number of the form 10n where n is an integer, so this will certainly work. Multiplying and dividing decimals by powers of 10