diff --git a/lib/mathops.c b/lib/mathops.c
index aadaa22a00bfd970124bd5d247bb89df660295dc..c9e4f8928d62a87c6947964c23039b9351505055 100644
--- a/lib/mathops.c
+++ b/lib/mathops.c
@@ -22,7 +22,7 @@ static const unsigned char OC_DEBRUIJN_IDX32[32]={
 
 int oc_ilog32(ogg_uint32_t _v){
 #if defined(OC_CLZ32)
-  return OC_CLZ32_OFFS-OC_CLZ32(_v)&-!!_v;
+  return _v ? (OC_CLZ32_OFFS-OC_CLZ32(_v)) : 0;
 #else
 /*On a Pentium M, this branchless version tested as the fastest version without
    multiplications on 1,000,000,000 random 32-bit integers, edging out a
@@ -62,8 +62,8 @@ int oc_ilog32(ogg_uint32_t _v){
 }
 
 int oc_ilog64(ogg_int64_t _v){
-#if defined(OC_CLZ64)
-  return OC_CLZ64_OFFS-OC_CLZ64(_v)&-!!_v;
+#if defined(CLZ64)
+  return _v ? CLZ64_OFFS-CLZ64(_v) : 0;
 #else
 /*If we don't have a fast 64-bit word implementation, split it into two 32-bit
    halves.*/
diff --git a/lib/mathops.h b/lib/mathops.h
index 2776dbd6dff54846ec31126464032eae6934ebb4..f821f850cb8cf5e5ce40bd48f72f23176a50580b 100644
--- a/lib/mathops.h
+++ b/lib/mathops.h
@@ -67,7 +67,7 @@ int oc_ilog64(ogg_int64_t _v);
  * This is the number of bits that would be required to represent _v in two's
  *  complement notation with all of the leading zeros stripped.
  */
-#  define OC_ILOG_32(_v)   (OC_ILOGNZ_32(_v)&-!!(_v))
+#  define OC_ILOG_32(_v)   ((_v)?OC_ILOGNZ_32(_v):0)
 # else
 #  define OC_ILOGNZ_32(_v) (oc_ilog32(_v))
 #  define OC_ILOG_32(_v)   (oc_ilog32(_v))
@@ -90,7 +90,7 @@ int oc_ilog64(ogg_int64_t _v);
  * This is the number of bits that would be required to represent _v in two's
  *  complement notation with all of the leading zeros stripped.
  */
-#  define OC_ILOG_64(_v)   (OC_ILOGNZ_64(_v)&-!!(_v))
+#  define OC_ILOG_64(_v)   ((_v)?OC_ILOGNZ_64(_v):0)
 # else
 #  define OC_ILOGNZ_64(_v) (oc_ilog64(_v))
 #  define OC_ILOG_64(_v)   (oc_ilog64(_v))