summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bignum.c7
-rw-r--r--numeric.c8
2 files changed, 15 insertions, 0 deletions
diff --git a/bignum.c b/bignum.c
index daaff252b6..3f1bb38341 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6999,6 +6999,13 @@ rb_big_size(VALUE big)
* (2**10000).bit_length #=> 10001
* (2**10000+1).bit_length #=> 10001
*
+ * This method can be used to detect overflow in Array#pack as follows.
+ *
+ * if n.bit_length < 32
+ * [n].pack("l") # no overflow
+ * else
+ * raise "overflow"
+ * end
*/
static VALUE
diff --git a/numeric.c b/numeric.c
index cc9c63e3d1..4bb2c3a534 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3538,6 +3538,14 @@ fix_size(VALUE fix)
* (2**12-1).bit_length #=> 12
* (2**12).bit_length #=> 13
* (2**12+1).bit_length #=> 13
+ *
+ * This method can be used to detect overflow in Array#pack as follows.
+ *
+ * if n.bit_length < 32
+ * [n].pack("l") # no overflow
+ * else
+ * raise "overflow"
+ * end
*/
static VALUE