Hmm ... Python:
>>> len(5) Traceback (most recent call last): File "<pyshell#45>", line 1, in <module> len(5) TypeError: object of type 'int' has no len()
Not what you wanted?
ok, let's assume you have an actual integer. base 10 of the log will tell you what you want to know numerically, that is, if yournumber == pow(10, digits) , then log10(yournumber) == digits ! unfortunately, if your number is not an exact capacity of 10, you will have a fraction to deal with. It's easy enough to handle the floor() function, which is simply rounded. beware of negative numbers, as the logarithms are undefined in real numbers for non-positive values.
#include <iostream> #include <math.h> int main() { std::cout << floor(log10(5))+1 << std::endl; std::cout << floor(log10(30))+1 << std::endl; std::cout << floor(log10(2000))+1 << std::endl; std::cout << floor(log10(16000))+1 << std::endl; }
we have to add 1, because 10 to 1 is still 10, so we are disabled by one. Add one to the exponent and you have the numbers!
SingleNegationElimination
source share