in reply to Re: reliably test integer size for portable bit-fiddling? (~0)
in thread reliably test integer size for portable bit-fiddling?

Beautiful use of the Maths. ;)


Dave

  • Comment on Re^2: reliably test integer size for portable bit-fiddling? (~0)

Replies are listed 'Best First'.
Re^3: reliably test integer size for portable bit-fiddling? (~0)
by Anonymous Monk on Dec 09, 2014 at 00:53 UTC
    *cough*
    $ perl -E " say log(~0)/log(2) " 31.9999999996641 $ perl -E " say int 0.999+log(~0)/log(2) " 32
      $ perl -le "print log(~0+1)/log(2)" 32

      or, to be safe

      $ perl -e 'printf "%.0f\n", log(~0+1)/log(2)' 32

      - tye