Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- rm -r a.out
- g++ -x c++ -std=c++11 - <<EOF
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- #include <math.h>
- static inline float fasterlog2 (float x)
- {
- union
- {
- float f;
- uint32_t i;
- } vx = { x };
- return vx.i * 1.1920928955078125e-7f - 126.94269504f;
- }
- static inline float fasterlog10(float x)
- {
- constexpr static float multiplier = 1 / log2(10);
- return fasterlog2(x) * multiplier;
- }
- inline size_t __decimal_digits(size_t value)
- { return fasterlog10(value) + 1; }
- int main() {
- size_t i, s1, s2, cnt=0;
- char text[100] = "";
- for(i=0;i<100000;i++) {
- sprintf(text, "%zu", i);
- s1 = strlen(text);
- s2 = __decimal_digits(i);
- if(s1!=s2)
- printf("%4i, %zu, s1=%zu, s2=%zu\n", cnt++, i, s1, s2);
- }
- printf("end...\n");
- return 0;
- }
- EOF
- ./a.out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement