![]() For example by storing only even powers of 10 and multiply by 10 when the exponent is odd, the table size is now only a half. You can also reduce the lookup table size further if memory is a constraint. If negative exponents is not needed then the final branch can be removed. You can get larger powers of 10 at runtime from the above lookup table to quickly get the result without needing to multiply by 10 again and again, but the result is just a value close to a power of 10 like when you use 10eX with X > 22 double pow10(int x) If you want to populate the values at compile time and then use them later at runtime then simply use a lookup table because there are only 23 different powers of 10 that are exactly representable in double precision double POW10 = If you just need to use the value at compile time, use the scientific notation like 1e2 for pow(10, 2) Powers of 10 are any number that can be achieved by multiplying 10 times itself. $ cat foo.c | m4 - | gcc -x c -o m4_pow. The command line to compile this code sample uses the ability of GCC and M4 to read from the standard input. $ cat foo.cĭefine(M4_POW_AUX, `ifelse($2, 1, $1, `eval($1 * M4_POW_AUX($1, decr($2)))')')dnlĭefine(M4_POW, `ifelse($2, 0, 1, `M4_POW_AUX($1, $2)')')dnl 10 to the Power of 4 There are a number of ways this can be expressed and the most common ways youll see 10 to the 4th shown are: 10 4 104 So basically, youll either see the exponent using superscript (to make it smaller and slightly above the base number) or youll use the caret symbol () to signify the exponent. This way, your code is kept from ugly intrusive M4 definitions into the C source code I've done here. ![]() The below code sample is what you would like to do, isn’t it? I made it bulky in a one-file source but I usually put M4's macro definitions in separate files and tune my Makefile rules. Power of 10, Power of ten, or Powers of Ten may refer to. It makes possible things like doing arithmetic at compile-time (and much more!). A power of 10 is any of the integer powers of the number ten in other words, ten multiplied by itself a certain number of times. A main difference between those two is GCC’s is not recursive whereas M4 is. Actually, you have M4 which is a pre-processor way more powerful than the GCC’s.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |