summaryrefslogtreecommitdiff
path: root/include/ruby/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/ruby/util.h')
-rw-r--r--include/ruby/util.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/include/ruby/util.h b/include/ruby/util.h
index b2bc1a09f6..12e69c4b80 100644
--- a/include/ruby/util.h
+++ b/include/ruby/util.h
@@ -19,7 +19,7 @@
# include <stddef.h> /* size_t */
#endif
-#if HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> /* ssize_t */
#endif
@@ -33,9 +33,20 @@
RBIMPL_SYMBOL_EXPORT_BEGIN()
-/** an approximation of ceil(n * log10(2)), up to 65536 at least */
+/** an approximation of ceil(n * log10(2)), up to 1,048,576 (1<<20)
+ * without overflow within 32-bit calculation
+ */
#define DECIMAL_SIZE_OF_BITS(n) (((n) * 3010 + 9998) / 9999)
+/** an approximation of decimal representation size for n-bytes */
+#define DECIMAL_SIZE_OF_BYTES(n) DECIMAL_SIZE_OF_BITS((n) * CHAR_BIT)
+
+/**
+ * An approximation of decimal representation size. `expr` may be a
+ * type name
+ */
+#define DECIMAL_SIZE_OF(expr) DECIMAL_SIZE_OF_BYTES(sizeof(expr))
+
/**
* Character to number mapping like `'a'` -> `10`, `'b'` -> `11` etc. For
* punctuation etc., the value is -1. "36" terminology comes from the fact
@@ -124,7 +135,7 @@ unsigned long ruby_scan_hex(const char *str, size_t len, size_t *ret);
# define ruby_qsort qsort_r
#else
void ruby_qsort(void *, const size_t, const size_t,
- int (*)(const void *, const void *, void *), void *);
+ int (*)(const void *, const void *, void *), void *);
#endif
RBIMPL_ATTR_NONNULL((1))