[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] intprops: new macro INT_BITS_STRLEN_BOUND
From: |
Paul Eggert |
Subject: |
[PATCH] intprops: new macro INT_BITS_STRLEN_BOUND |
Date: |
Wed, 17 Nov 2010 16:32:19 -0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101027 Thunderbird/3.0.10 |
* lib/intprops.h (INT_BITS_STRLEN_BOUND): New macro, needed by
ftoastr.h. This exposes an internal of intprops.h that was formerly
not exposed. Also, it uses a slightly tighter bound than before;
though this makes no practical difference, we might as well be as
tight as we easily can.
---
ChangeLog | 7 +++++++
lib/intprops.h | 14 +++++++++-----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ea0610a..0ab0af3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2010-11-17 Paul Eggert <address@hidden>
+ intprops: new macro INT_BITS_STRLEN_BOUND
+ * lib/intprops.h (INT_BITS_STRLEN_BOUND): New macro, needed by
+ ftoastr.h. This exposes an internal of intprops.h that was formerly
+ not exposed. Also, it uses a slightly tighter bound than before;
+ though this makes no practical difference, we might as well be as
+ tight as we easily can.
+
ftoastr: new module, for lossless conversion of floats to short strings
* lib/ftoastr.h, lib/ftoastr.c, lib/dtoastr.c, lib/ldtoastr.c:
* modules/ftoastr: New files.
diff --git a/lib/intprops.h b/lib/intprops.h
index 46f4d47..0c27875 100644
--- a/lib/intprops.h
+++ b/lib/intprops.h
@@ -68,13 +68,17 @@
# define signed_type_or_expr__(t) 1
# endif
+/* Bound on length of the string representing an unsigned integer
+ value representable in B bits. log10 (2.0) < 146/485. The
+ smallest value of B where this bound is not tight is 2621. */
+# define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
+
/* Bound on length of the string representing an integer type or expression T.
- Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485;
- add 1 for integer division truncation; add 1 more for a minus sign
- if needed. */
+ Subtract 1 for the sign bit if T is signed, and then add 1 more for
+ a minus sign if needed. */
# define INT_STRLEN_BOUND(t) \
- ((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \
- + signed_type_or_expr__ (t) + 1)
+ (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) \
+ + signed_type_or_expr__ (t))
/* Bound on buffer size needed to represent an integer type or expression T,
including the terminating null. */
--
1.7.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] intprops: new macro INT_BITS_STRLEN_BOUND,
Paul Eggert <=