
awk's mod operator % question (application: log base2 non-integer result)
Quote:
>All:
> Non-inituitive query
>citing table 2-8 in the The Awk Language book
> x % y remainder of x divided by y
>Does y need to be an integer?
No. it returns the same thing as fmod, according to my man page. YMMV
BTW, why didn't you just test it?
echo 10.1 3.1 | awk '{print $1 % $2}'
produces
0.8
Chuck Demas
Needham, Mass.
Quote:
>I'm asking as I'm trying to evaluate log base 2 of a positive integer x
>and trying to determine what the non-integer portion of the following:
> log(x) / log(2)
>and round up log(x) / log(2) to the next integer
>if log(x) % log(2) is > 0.
>[If it's more optimal to convert x to binary, convert it to string,
> count the number of places bast the leftmost one to get
> the integer portion of the log base 2 of x, and bitwise or
> those rightmost places to detect a round-up, please post a
> solution/alternative...]
>regards,
>Jim Mrowca
--
Eat Healthy | _ _ | Nothing would be done at all,
Die Anyway | v | That no one could find fault with it.