]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(INT_STRLEN_BOUND): New macro.
authorJim Meyering <jim@meyering.net>
Sat, 17 Mar 2001 08:50:51 +0000 (08:50 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 17 Mar 2001 08:50:51 +0000 (08:50 +0000)
src/sys2.h

index 2ed46b16b7df9ea445baffb361bf2a18edad638c..48af648c3003c8d1da8095af0bdb0d3dfc0785ae 100644 (file)
@@ -488,6 +488,11 @@ enum
                              ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
 
+/* Upper bound on the string length of an integer converted to string.
+   302 / 1000 is ceil (log10 (2.0)).  Subtract 1 for the sign bit;
+   add 1 for integer division truncation; add 1 more for a minus sign.  */
+#define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2)
+
 #ifndef CHAR_MIN
 # define CHAR_MIN TYPE_MINIMUM (char)
 #endif