summaryrefslogtreecommitdiff
path: root/handy.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-05-29 14:25:19 -0600
committerKarl Williamson <khw@cpan.org>2020-07-17 22:04:08 -0600
commitd223e1ea9ae864c0e563187f1e76240ef1acad87 (patch)
treef670961d58ff3c055cff40637ca9daacaf1b462e /handy.h
parent0654f0ab17405d0d55f0006348b4ed0084aa1fc8 (diff)
downloadperl-d223e1ea9ae864c0e563187f1e76240ef1acad87.tar.gz
handy.h: Create nBIT_MASK(n) macro
This encapsulates a common paradigm, making sure that it is done correctly for the platform's size.
Diffstat (limited to 'handy.h')
-rw-r--r--handy.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/handy.h b/handy.h
index 4451e9d46d..7f0741732e 100644
--- a/handy.h
+++ b/handy.h
@@ -269,6 +269,13 @@ typedef U64TYPE U64;
# define isPOWER_OF_2(n) ((n) && ((n) & ((n)-1)) == 0)
#endif
+/* Returns a mask with the lowest n bits set */
+#ifdef HAS_LONG_LONG
+# define nBIT_MASK(n) ((1ULL << (n)) - 1)
+#else
+# define nBIT_MASK(n) ((1UL << (n)) - 1)
+#endif
+
/*
=for apidoc Am|void|__ASSERT_|bool expr