Advertisement
Guest User

Untitled

a guest
Aug 10th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. rm -r a.out
  4. g++ -x c++ -std=c++11 - <<EOF
  5. #include <stdio.h>
  6. #include <stdint.h>
  7. #include <string.h>
  8. #include <math.h>
  9. static inline float fasterlog2 (float x)
  10. {
  11. union
  12. {
  13. float f;
  14. uint32_t i;
  15. } vx = { x };
  16.  
  17. return vx.i * 1.1920928955078125e-7f - 126.94269504f;
  18. }
  19. static inline float fasterlog10(float x)
  20. {
  21. constexpr static float multiplier = 1 / log2(10);
  22. return fasterlog2(x) * multiplier;
  23. }
  24. inline size_t __decimal_digits(size_t value)
  25. { return fasterlog10(value) + 1; }
  26. int main() {
  27. size_t i, s1, s2, cnt=0;
  28. char text[100] = "";
  29. for(i=0;i<100000;i++) {
  30. sprintf(text, "%zu", i);
  31. s1 = strlen(text);
  32. s2 = __decimal_digits(i);
  33. if(s1!=s2)
  34. printf("%4i, %zu, s1=%zu, s2=%zu\n", cnt++, i, s1, s2);
  35. }
  36. printf("end...\n");
  37. return 0;
  38. }
  39. EOF
  40. ./a.out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement