~ubuntu-branches/ubuntu/trusty/libidn/trusty

« back to all changes in this revision

Viewing changes to gl/intprops.h

  • Committer: Bazaar Package Importer
  • Author(s): Simon Josefsson
  • Date: 2011-03-01 16:14:24 UTC
  • mfrom: (1.2.14 upstream) (3.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110301161424-6vh7822t8aderzap
Tags: 1.20-1
* New upstream release.
* Moved from experimental to unstable after testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* intprops.h -- properties of integer types
2
2
 
3
 
   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009, 2010 Free Software
4
 
   Foundation, Inc.
 
3
   Copyright (C) 2001-2005, 2009-2011 Free Software Foundation, Inc.
5
4
 
6
5
   This program is free software: you can redistribute it and/or modify
7
6
   it under the terms of the GNU General Public License as published by
50
49
        ? (t) 0 \
51
50
        : TYPE_SIGNED_MAGNITUDE (t) \
52
51
        ? ~ (t) 0 \
53
 
        : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
 
52
        : ~ TYPE_MAXIMUM (t)))
54
53
# define TYPE_MAXIMUM(t) \
55
54
  ((t) (! TYPE_SIGNED (t) \
56
55
        ? (t) -1 \
57
 
        : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
 
56
        : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
58
57
 
59
58
/* Return zero if T can be determined to be an unsigned type.
60
59
   Otherwise, return 1.
68
67
#  define signed_type_or_expr__(t) 1
69
68
# endif
70
69
 
 
70
/* Bound on length of the string representing an unsigned integer
 
71
   value representable in B bits.  log10 (2.0) < 146/485.  The
 
72
   smallest value of B where this bound is not tight is 2621.  */
 
73
# define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
 
74
 
71
75
/* Bound on length of the string representing an integer type or expression T.
72
 
   Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485;
73
 
   add 1 for integer division truncation; add 1 more for a minus sign
74
 
   if needed.  */
 
76
   Subtract 1 for the sign bit if T is signed, and then add 1 more for
 
77
   a minus sign if needed.  */
75
78
# define INT_STRLEN_BOUND(t) \
76
 
  ((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \
77
 
   + signed_type_or_expr__ (t) + 1)
 
79
  (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) \
 
80
   + signed_type_or_expr__ (t))
78
81
 
79
82
/* Bound on buffer size needed to represent an integer type or expression T,
80
83
   including the terminating null.  */