simplify numeric constraints checking in runtime
diff --git a/skeletons/INTEGER_oer.c b/skeletons/INTEGER_oer.c
index e730d68..b90698f 100644
--- a/skeletons/INTEGER_oer.c
+++ b/skeletons/INTEGER_oer.c
@@ -16,8 +16,8 @@
     asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics;
     asn_dec_rval_t rval = {RC_OK, 0};
     INTEGER_t *st = (INTEGER_t *)*sptr;
-    asn_oer_constraint_t *ct;
-    size_t req_bytes = 0; /* 0 = length determinant is required */
+    struct asn_oer_constraint_number_s ct = {0, 0};
+    size_t req_bytes;
 
     (void)opt_codec_ctx;
     (void)specs;
@@ -32,42 +32,33 @@
     st->size = 0;
 
     if(!constraints) constraints = td->oer_constraints;
-    ct = constraints ? &constraints->value : 0;
+    if(constraints) ct = constraints->value;
 
-    if(ct && (ct->flags & AOC_HAS_LOWER_BOUND) && ct->lower_bound >= 0) {
+    if(ct.width) {
+        req_bytes = ct.width;
+    } else {
+        /* No lower bound and no upper bound, effectively */
+
+        ssize_t consumed = oer_fetch_length(ptr, size, &req_bytes);
+        if(consumed == 0) {
+            ASN__DECODE_STARVED;
+        } else if(consumed == -1) {
+            ASN__DECODE_FAILED;
+        }
+        rval.consumed += consumed;
+        ptr = (const char *)ptr + consumed;
+        size -= consumed;
+    }
+
+    if(req_bytes > size) {
+        ASN__DECODE_STARVED;
+    }
+
+    if(ct.positive) {
         /* X.969 08/2015 10.2(a) */
         unsigned msb;   /* Most significant bit */
         size_t useful_size;
 
-        intmax_t ub = ct->upper_bound;
-        if(ct->flags & AOC_HAS_UPPER_BOUND) {
-            if(ub <= 255) {
-                req_bytes = 1;
-            } else if(ub <= 65535) {
-                req_bytes = 2;
-            } else if(ub <= 4294967295UL) {
-                req_bytes = 4;
-            } else if(ub <= 18446744073709551615ULL) {
-                req_bytes = 8;
-            }
-        }
-
-        if(req_bytes == 0) {    /* #8.6, using length determinant */
-            ssize_t consumed = oer_fetch_length(ptr, size, &req_bytes);
-            if(consumed == 0) {
-                ASN__DECODE_STARVED;
-            } else if(consumed == -1) {
-                ASN__DECODE_FAILED;
-            }
-            rval.consumed += consumed;
-            ptr = (const char *)ptr + consumed;
-            size -= consumed;
-        }
-
-        if(req_bytes > size) {
-            ASN__DECODE_STARVED;
-        }
-
         /* Check most significant bit */
         msb = *(const uint8_t *)ptr >> 7; /* yields 0 or 1 */
         useful_size = msb + req_bytes;
@@ -87,55 +78,20 @@
 
         rval.consumed += req_bytes;
         return rval;
-    } else if(ct
-              && ((ct->flags
-                  & (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND))
-                        == (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND))) {
-        /* X.969 08/2015 10.2(b) - no lower bound or negative lower bound */
-
-        intmax_t lb = ct->lower_bound;
-        intmax_t ub = ct->upper_bound;
-
-        if(lb >= -128 && ub <= 127) {
-            req_bytes = 1;
-        } else if(lb >= -32768 && ub <= 32767) {
-            req_bytes = 2;
-        } else if(lb >= -2147483648L && ub <= 2147483647L) {
-            req_bytes = 4;
-        } else if(lb >= -9223372036854775808LL && ub <= 9223372036854775807LL) {
-            req_bytes = 8;
-        }
-    }
-
-    /* No lower bound and no upper bound, effectively */
-
-    if(req_bytes == 0) {    /* #8.6, using length determinant */
-        ssize_t consumed = oer_fetch_length(ptr, size, &req_bytes);
-        if(consumed == 0) {
-            ASN__DECODE_STARVED;
-        } else if(consumed == -1) {
+    } else {
+        /* X.969 08/2015 10.2(b) */
+        st->buf = (uint8_t *)MALLOC(req_bytes + 1);
+        if(!st->buf) {
             ASN__DECODE_FAILED;
         }
-        rval.consumed += consumed;
-        ptr = (const char *)ptr + consumed;
-        size -= consumed;
+
+        memcpy(st->buf, ptr, req_bytes);
+        st->buf[req_bytes] = '\0'; /* Just in case, 0-terminate */
+        st->size = req_bytes;
+
+        rval.consumed += req_bytes;
+        return rval;
     }
-
-    if(req_bytes > size) {
-        ASN__DECODE_STARVED;
-    }
-
-    st->buf = (uint8_t *)MALLOC(req_bytes + 1);
-    if(!st->buf) {
-        ASN__DECODE_FAILED;
-    }
-
-    memcpy(st->buf, ptr, req_bytes);
-    st->buf[req_bytes] = '\0'; /* Just in case, 0-terminate */
-    st->size = req_bytes;
-
-    rval.consumed += req_bytes;
-    return rval;
 }
 
 /*
@@ -147,31 +103,27 @@
                    asn_app_consume_bytes_f *cb, void *app_key) {
     const INTEGER_t *st = sptr;
     asn_enc_rval_t er;
-    asn_oer_constraint_t *ct;
+    struct asn_oer_constraint_number_s ct = {0, 0};
     const uint8_t *buf;
     const uint8_t *end;
     size_t useful_bytes;
     size_t req_bytes = 0;
-    int encode_as_unsigned;
     int sign = 0;
 
     if(!st || st->size == 0) ASN__ENCODE_FAILED;
 
     if(!constraints) constraints = td->oer_constraints;
-    ct = constraints ? &constraints->value : 0;
+    if(constraints) ct = constraints->value;
 
     er.encoded = 0;
 
     buf = st->buf;
     end = buf + st->size;
 
-    encode_as_unsigned =
-        ct && (ct->flags & AOC_HAS_LOWER_BOUND) && ct->lower_bound >= 0;
-
     sign = (buf && buf < end) ? buf[0] & 0x80 : 0;
 
     /* Ignore 9 leading zeroes or ones */
-    if(encode_as_unsigned) {
+    if(ct.positive) {
         if(sign) {
             /* The value given is a signed value. Can't proceed. */
             ASN__ENCODE_FAILED;
@@ -192,46 +144,18 @@
     }
 
     useful_bytes = end - buf;
-    if(encode_as_unsigned) {
-        intmax_t ub = ct->upper_bound;
-
-        if(ub <= 255) {
-            req_bytes = 1;
-        } else if(ub <= 65535) {
-            req_bytes = 2;
-        } else if(ub <= 4294967295UL) {
-            req_bytes = 4;
-        } else if(ub <= 18446744073709551615ULL) {
-            req_bytes = 8;
-        }
-    } else if(ct
-              && ((ct->flags
-                  & (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND))
-                        == (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND))) {
-        /* X.969 08/2015 10.2(b) - no lower bound or negative lower bound */
-
-        intmax_t lb = ct->lower_bound;
-        intmax_t ub = ct->upper_bound;
-
-        if(lb >= -128 && ub <= 127) {
-            req_bytes = 1;
-        } else if(lb >= -32768 && ub <= 32767) {
-            req_bytes = 2;
-        } else if(lb >= -2147483648L && ub <= 2147483647L) {
-            req_bytes = 4;
-        } else if(lb >= -9223372036854775808LL && ub <= 9223372036854775807LL) {
-            req_bytes = 8;
-        }
-    }
-
-    if(req_bytes == 0) {
+    if(ct.width) {
+        req_bytes = ct.width;
+    } else {
         ssize_t r = oer_serialize_length(useful_bytes, cb, app_key);
         if(r < 0) {
             ASN__ENCODE_FAILED;
         }
         er.encoded += r;
         req_bytes = useful_bytes;
-    } else if(req_bytes < useful_bytes) {
+    }
+
+    if(req_bytes < useful_bytes) {
         ASN__ENCODE_FAILED;
     }
 
diff --git a/skeletons/NativeInteger_oer.c b/skeletons/NativeInteger_oer.c
index f9b505f..7633a77 100644
--- a/skeletons/NativeInteger_oer.c
+++ b/skeletons/NativeInteger_oer.c
@@ -17,22 +17,16 @@
     asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics;
     asn_dec_rval_t rval = {RC_OK, 0};
     long *native = (long *)*nint_ptr;
-    asn_oer_constraint_t *ct;
     INTEGER_t tmpint;
     INTEGER_t *tmpintptr = &tmpint;
 
     memset(&tmpint, 0, sizeof(tmpint));
 
-    (void)opt_codec_ctx;
-
     if(!native) {
         native = (long *)(*nint_ptr = CALLOC(1, sizeof(*native)));
         if(!native) ASN__DECODE_FAILED;
     }
 
-    if(!constraints) constraints = td->oer_constraints;
-    ct = constraints ? &constraints->value : 0;
-
     /*
      * OPTIMIZATION: Encode directly rather than passing through INTEGER.
      * Saves a memory allocation.
diff --git a/skeletons/OCTET_STRING_oer.c b/skeletons/OCTET_STRING_oer.c
index 1b1e234..9f878d1 100644
--- a/skeletons/OCTET_STRING_oer.c
+++ b/skeletons/OCTET_STRING_oer.c
@@ -9,11 +9,6 @@
 #include <OCTET_STRING.h>
 #include <errno.h>
 
-static asn_oer_constraints_t asn_DEF_OCTET_STRING_oer_constraints = {
-        { 0, 0, 0 },
-        { AOC_HAS_LOWER_BOUND, 0, 0 }
-};
-
 asn_dec_rval_t
 OCTET_STRING_decode_oer(asn_codec_ctx_t *opt_codec_ctx,
                          asn_TYPE_descriptor_t *td,
@@ -26,8 +21,7 @@
     OCTET_STRING_t *st = (OCTET_STRING_t *)*sptr;
     asn_oer_constraints_t *cts =
         constraints ? constraints : td->oer_constraints;
-    asn_oer_constraint_t *csiz =
-        cts ? &cts->size : &asn_DEF_OCTET_STRING_oer_constraints.size;
+    ssize_t ct_size = cts ? cts->size : -1;
     asn_dec_rval_t rval = {RC_OK, 0};
     size_t expected_length = 0;
 
@@ -57,11 +51,8 @@
         if(!st) ASN__DECODE_FAILED;
     }
 
-    if((csiz->flags
-           & (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND))
-                 == (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND)
-       && csiz->lower_bound == csiz->upper_bound) {
-        expected_length = unit_bytes * csiz->lower_bound;
+    if(ct_size >= 0) {
+        expected_length = unit_bytes * ct_size;
     } else {
         /*
          * X.696 (08/2015) #27.2
@@ -120,18 +111,14 @@
     OCTET_STRING_t *st = (OCTET_STRING_t *)sptr;
     asn_oer_constraints_t *cts =
         constraints ? constraints : td->oer_constraints;
-    asn_oer_constraint_t *csiz =
-        cts ? &cts->size : &asn_DEF_OCTET_STRING_oer_constraints.size;
+    ssize_t ct_size = cts ? cts->size : -1;
     asn_enc_rval_t er = {0, 0, 0};
 
     if(!st) ASN__ENCODE_FAILED;
 
     ASN_DEBUG("Encoding %s %d as OCTET STRING", td ? td->name : "", st->size);
 
-    if((csiz->flags
-           & (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND))
-                 == (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND)
-       && csiz->lower_bound == csiz->upper_bound) {
+    if(ct_size >= 0) {
         /*
          * Check that available data matches the constraint
          */
@@ -154,11 +141,11 @@
             break;
         }
 
-        if(st->size != unit_bytes * csiz->lower_bound) {
+        if(st->size != unit_bytes * ct_size) {
             ASN_DEBUG(
                 "Trying to encode %s (%zu bytes) which doesn't fit SIZE "
                 "constraint (%d)",
-                td->name, st->size, csiz->lower_bound);
+                td->name, st->size, ct_size);
             ASN__ENCODE_FAILED;
         }
     } else {
diff --git a/skeletons/oer_support.h b/skeletons/oer_support.h
index 2a7fcb9..a529254 100644
--- a/skeletons/oer_support.h
+++ b/skeletons/oer_support.h
@@ -15,17 +15,13 @@
 /*
  * Pre-computed OER constraints.
  */
-typedef const struct asn_oer_constraint_s {
-	enum asn_oer_constraint_flags {
-		AOC_HAS_LOWER_BOUND = 0x01,
-		AOC_HAS_UPPER_BOUND = 0x02
-	} flags;
-	intmax_t lower_bound;
-	intmax_t upper_bound;
-} asn_oer_constraint_t;
+typedef const struct asn_oer_constraint_number_s {
+    unsigned width;    /* ±8,4,2,1 fixed bytes */
+    unsigned positive; /* 1 for unsigned number, 0 for signed */
+} asn_oer_constraint_number_t;
 typedef const struct asn_oer_constraints_s {
-    struct asn_oer_constraint_s value;
-    struct asn_oer_constraint_s size;
+    asn_oer_constraint_number_t value;
+    ssize_t size;    /* -1 (no constraint) or >= 0 */
 } asn_oer_constraints_t;
 
 
diff --git a/skeletons/tests/check-OER-INTEGER.c b/skeletons/tests/check-OER-INTEGER.c
index 3658e7c..314b6b3 100644
--- a/skeletons/tests/check-OER-INTEGER.c
+++ b/skeletons/tests/check-OER-INTEGER.c
@@ -9,53 +9,24 @@
 #define CHECK_ENCODE_OK(a, b, c) check_encode(__LINE__, 0, a, b, c)
 #define CHECK_ENCODE_BAD(a, b, c) check_encode(__LINE__, 1, a, b, c);
 
-static const intmax_t NoBound = -4200024;
-
 static asn_oer_constraints_t *
-setup_constraints(int lineno, const char *process, intmax_t lower_bound,
-                  intmax_t upper_bound) {
+setup_constraints(int lineno, const char *process, unsigned width,
+                  unsigned positive) {
     static struct asn_oer_constraints_s empty_constraints;
     struct asn_oer_constraints_s *constraints = &empty_constraints;
-    struct asn_oer_constraint_s *ct_value = &constraints->value;
+    struct asn_oer_constraint_number_s *ct_value = &constraints->value;
 
     memset(&empty_constraints, 0, sizeof(empty_constraints));
 
     /* Setup integer constraints as requested */
-    if(lower_bound == NoBound && upper_bound == NoBound) {
-        fprintf(stderr, "%d: OER %s without constraints\n", lineno,
-                process);
-        constraints = NULL;
-    } else {
-        if(lower_bound != NoBound) {
-            ct_value->flags |= AOC_HAS_LOWER_BOUND;
-            ct_value->lower_bound = lower_bound;
-        }
-        if(upper_bound != NoBound) {
-            ct_value->flags |= AOC_HAS_UPPER_BOUND;
-            ct_value->upper_bound = upper_bound;
-        }
-        if(lower_bound != NoBound && upper_bound != NoBound) {
-            fprintf(stderr,
-                    "%d: OER %s constraints %" PRIdMAX
-                    "..%" PRIdMAX "\n",
-                    lineno, process, lower_bound, upper_bound);
-        } else if(lower_bound != NoBound) {
-            fprintf(stderr,
-                    "%d: OER %s constraints %" PRIdMAX
-                    "..MAX\n",
-                    lineno, process, lower_bound);
-        } else if(upper_bound != NoBound) {
-            fprintf(stderr,
-                    "%d: OER %s constraints MIN..%" PRIdMAX "\n",
-                    lineno, process, upper_bound);
-        }
-    }
+    ct_value->width = width;
+    ct_value->positive = positive;
 
     return constraints;
 }
 
 static void
-check_decode(int lineno, enum asn_dec_rval_code_e code, intmax_t control, const char *buf, size_t size, const char *dummy, intmax_t lower_bound, intmax_t upper_bound) {
+check_decode(int lineno, enum asn_dec_rval_code_e code, intmax_t control, const char *buf, size_t size, const char *dummy, unsigned width, unsigned positive) {
     static char *code_s[] = { "RC_OK", "RC_WMORE", "RC_FAIL", "<error>" };
 
     fprintf(stderr, "\n%d: OER decode (control %" PRIdMAX ")\n", lineno, control);
@@ -63,7 +34,7 @@
     INTEGER_t *st = NULL;
     asn_dec_rval_t ret;
     asn_oer_constraints_t *constraints =
-        setup_constraints(lineno, "decoding", lower_bound, upper_bound);
+        setup_constraints(lineno, "decoding", width, positive);
 
     fprintf(stderr, "%d: buf[%zu]={%d, %d, ...}\n", lineno, size,
             ((const uint8_t *)buf)[0],
@@ -186,7 +157,7 @@
 }
 
 static void
-check_encode(int lineno, int bad, intmax_t value, intmax_t lower_bound, intmax_t upper_bound) {
+check_encode(int lineno, int bad, intmax_t value, unsigned width, unsigned positive) {
     uint8_t tmpbuf[32];
 
     fprintf(stderr, "\n%d: OER encode value %" PRIdMAX "\n", lineno, value);
@@ -194,7 +165,7 @@
     INTEGER_t *stOut = (INTEGER_t *)calloc(1, sizeof(*stOut));
     asn_enc_rval_t er;
     asn_oer_constraints_t *constraints =
-        setup_constraints(lineno, "encoding", lower_bound, upper_bound);
+        setup_constraints(lineno, "encoding", width, positive);
 
     if(asn_imax2INTEGER(stOut, value) == -1) {
         assert(!"Unreachable imax2INTEGER failure");
@@ -223,96 +194,104 @@
 
 int
 main() {
-	CHECK_DECODE(RC_WMORE, 0, "", 0, "bounds=", NoBound, NoBound);
-	CHECK_DECODE(RC_FAIL, 0, "\x00", 1, "bounds=", NoBound, NoBound);
 	CHECK_DECODE(RC_WMORE, 0, "", 0, "bounds=", 0, 0);
-	CHECK_DECODE(RC_WMORE, 0, "", 0, "bounds=", 0, 1);
-	CHECK_DECODE(RC_OK, 0, "\x00", 1, "bounds=", 0, 1);
-	CHECK_DECODE(RC_OK, 0, "\x00", 1, "bounds=", -1, 1);
+	CHECK_DECODE(RC_FAIL, 0, "\x00", 1, "bounds=", 0, 0);
+	CHECK_DECODE(RC_WMORE, 0, "", 0, "bounds=", 1, 0);
+	CHECK_DECODE(RC_WMORE, 0, "", 0, "bounds=", 1, 1);
+	CHECK_DECODE(RC_OK, 0, "\x00", 1, "bounds=", 1, 1);
+	CHECK_DECODE(RC_OK, 0, "\x00", 1, "bounds=", 1, 0);
 
-	CHECK_DECODE(RC_OK, 0, "\x00", 1, "bounds=", -1, 1);
-	CHECK_DECODE(RC_OK, 1, "\x01", 1, "bounds=", -1, 1);
-	CHECK_DECODE(RC_OK, -1, "\xff", 1, "bounds=", -1, 1);
-	CHECK_DECODE(RC_OK, -1, "\xff", 1, "bounds=", -1, 1);
-	CHECK_DECODE(RC_OK, 127, "\x7f", 1, "bounds=", 0, 127);
-	CHECK_DECODE(RC_OK, 255, "\xff", 1, "bounds=", 0, 127);
-	CHECK_DECODE(RC_OK, 255, "\xff", 1, "bounds=", 0, 255);
-	CHECK_DECODE(RC_WMORE, 0, "\xff", 1, "bounds=", 0, 256);
-	CHECK_DECODE(RC_OK, 65535, "\xff\xff", 2, "bounds=", 0, 256);
+	CHECK_DECODE(RC_OK, 0, "\x00", 1, "bounds=", 1, 0);
+	CHECK_DECODE(RC_OK, 1, "\x01", 1, "bounds=", 1, 0);
+	CHECK_DECODE(RC_OK, -1, "\xff", 1, "bounds=", 1, 0);
+	CHECK_DECODE(RC_OK, -1, "\xff", 1, "bounds=", 1, 0);
+	CHECK_DECODE(RC_OK, 127, "\x7f", 1, "bounds=", 1, 1);
+	CHECK_DECODE(RC_OK, 255, "\xff", 1, "bounds=", 1, 1);
+	CHECK_DECODE(RC_OK, 255, "\xff", 1, "bounds=", 1, 1);
+	CHECK_DECODE(RC_WMORE, 0, "\xff", 1, "bounds=", 2, 1);
+	CHECK_DECODE(RC_OK, 65535, "\xff\xff", 2, "bounds=", 2, 1);
 
-	CHECK_DECODE(RC_OK, 0, "\x01\x00", 2, "bounds=", NoBound, 1);
-	CHECK_DECODE(RC_OK, 1, "\x01\x01", 2, "bounds=", NoBound, 1);
-	CHECK_DECODE(RC_OK, -1, "\x1\xff", 2, "bounds=", NoBound, 1);
-	CHECK_DECODE(RC_OK, -1, "\x1\xff", 2, "bounds=", NoBound, 1);
-	CHECK_DECODE(RC_OK, -1, "\x1\xff", 2, "bounds=", NoBound, 255);
-	CHECK_DECODE(RC_WMORE, -1, "\x02\x00\xff", 2, "bounds=", NoBound, 200);
-	CHECK_DECODE(RC_OK, 255, "\x02\x00\xff", 3, "bounds=", NoBound, 200);
+	CHECK_DECODE(RC_OK, 0, "\x01\x00", 2, "bounds=", 0, 0);
+	CHECK_DECODE(RC_OK, 1, "\x01\x01", 2, "bounds=", 0, 0);
+	CHECK_DECODE(RC_OK, -1, "\x1\xff", 2, "bounds=", 0, 0);
+	CHECK_DECODE(RC_OK, -1, "\x1\xff", 2, "bounds=", 0, 0);
+	CHECK_DECODE(RC_OK, -1, "\x1\xff", 2, "bounds=", 0, 0);
+	CHECK_DECODE(RC_OK, 255, "\x1\xff", 2, "bounds=", 0, 1);
+	CHECK_DECODE(RC_WMORE, -1, "\x02\x00\xff", 2, "bounds=", 0, 0);
+	CHECK_DECODE(RC_OK, 255, "\x02\x00\xff", 3, "bounds=", 0, 0);
 
-    CHECK_ROUNDTRIP(0, NoBound, NoBound);
-    CHECK_ROUNDTRIP(1, NoBound, NoBound);
-    CHECK_ROUNDTRIP(-1, NoBound, NoBound);
-    CHECK_ROUNDTRIP(-65000, NoBound, NoBound);
-    CHECK_ROUNDTRIP(65000, NoBound, NoBound);
-    CHECK_ROUNDTRIP(65535, NoBound, NoBound);
-    CHECK_ROUNDTRIP(-65535, NoBound, NoBound);
-    CHECK_ROUNDTRIP(-65536, NoBound, NoBound);
-    CHECK_ROUNDTRIP(65536, NoBound, NoBound);
-    CHECK_ROUNDTRIP(0, -128, 127);
-    CHECK_ROUNDTRIP(1, -128, 127);
-    CHECK_ROUNDTRIP(-1, -128, 127);
-    CHECK_ROUNDTRIP(-127, -128, 127);
-    CHECK_ROUNDTRIP(-128, -128, 127);
-    CHECK_ROUNDTRIP(127, -128, 127);
-    CHECK_ROUNDTRIP(1, 32000, 32000);   /* Sic! */
-    CHECK_ROUNDTRIP(32000, 0, 32000);  /* Sic! */
-    CHECK_ROUNDTRIP(32000, -32000, 32000);  /* Sic! */
-    CHECK_ROUNDTRIP(1, 65000, 65000);   /* Sic! */
-    CHECK_ROUNDTRIP(65535, 0, 65000);  /* Sic! */
-    CHECK_ROUNDTRIP(65535, -65000, 65000);  /* Sic! */
+    CHECK_ROUNDTRIP(0, 0, 0);
+    CHECK_ROUNDTRIP(1, 0, 0);
+    CHECK_ROUNDTRIP(-1, 0, 0);
+    CHECK_ROUNDTRIP(-65000, 0, 0);
+    CHECK_ROUNDTRIP(65000, 0, 0);
+    CHECK_ROUNDTRIP(65535, 0, 0);
+    CHECK_ROUNDTRIP(-65535, 0, 0);
+    CHECK_ROUNDTRIP(-65536, 0, 0);
+    CHECK_ROUNDTRIP(65536, 0, 0);
+    CHECK_ROUNDTRIP(0, 1, 0);
+    CHECK_ROUNDTRIP(1, 1, 0);
+    CHECK_ROUNDTRIP(-1, 1, 0);
+    CHECK_ROUNDTRIP(-127, 1, 0);
+    CHECK_ROUNDTRIP(-128, 1, 0);
+    CHECK_ROUNDTRIP(127, 1, 0);
+    CHECK_ROUNDTRIP(1, 2, 1);
+    CHECK_ROUNDTRIP(32000, 2, 1);
+    CHECK_ROUNDTRIP(32000, 2, 0);
+    CHECK_ROUNDTRIP(1, 2, 1);
+    CHECK_ROUNDTRIP(65535, 2, 1);
+    CHECK_ROUNDTRIP(65535, 4, 0);
 
-    CHECK_ENCODE_OK(0, 0, 255);
-    CHECK_ENCODE_OK(255, 0, 255);
-    CHECK_ENCODE_BAD(256, 0, 255);
-    CHECK_ENCODE_OK(0, -128, 127);
-    CHECK_ENCODE_OK(127, -128, 127);
-    CHECK_ENCODE_OK(-128, -128, 127);
-    CHECK_ENCODE_BAD(-129, -128, 127);
-    CHECK_ENCODE_BAD(128, -128, 127);
-    CHECK_ENCODE_OK(-4900000000, -5000000000, 5000000000);
-    CHECK_ENCODE_OK(4900000000, -5000000000, 5000000000);
-    CHECK_ENCODE_OK(-2000000000, -4000000000, 0);
-    CHECK_ENCODE_OK(-4000000000, -4000000000, 0);
-    CHECK_ENCODE_BAD(-4900000000, 0, 4000000000);
+    CHECK_ENCODE_OK(0, 1, 1);
+    CHECK_ENCODE_OK(255, 1, 1);
+    CHECK_ENCODE_BAD(256, 1, 1);
+    CHECK_ENCODE_OK(0, 1, 0);
+    CHECK_ENCODE_OK(127, 1, 0);
+    CHECK_ENCODE_OK(-128, 1, 0);
+    CHECK_ENCODE_BAD(-129, 1, 0);
+    CHECK_ENCODE_BAD(128, 1, 0);
+    CHECK_ENCODE_OK(-4900000000, 8, 0);
+    CHECK_ENCODE_OK(4900000000, 8, 0);
+    CHECK_ENCODE_OK(-2000000000, 8, 0);
+    CHECK_ENCODE_OK(-4000000000, 8, 0);
+    CHECK_ENCODE_BAD(-4900000000, 4, 1);
     CHECK_ENCODE_BAD(-1, 0, 4000000000);
-    CHECK_ENCODE_BAD(4900000000, 0, 4000000000);
-    CHECK_ENCODE_OK(4100000000, 0, 4000000000); /* Sic! */
+    CHECK_ENCODE_BAD(4900000000, 4, 1);
+    CHECK_ENCODE_OK(4100000000, 4, 1);
 
     for(size_t i = 0; i < 7 ; i++) {
         intmax_t value = (intmax_t)1 << i;
-        CHECK_ROUNDTRIP(value, 0, 255);
+        CHECK_ROUNDTRIP(value, 1, 1);
         value = -value;
-        CHECK_ROUNDTRIP(value, -128, 127);
+        CHECK_ROUNDTRIP(value, 1, 0);
     }
 
     for(size_t i = 0; i < 16 ; i++) {
         intmax_t value = (intmax_t)1 << i;
-        CHECK_ROUNDTRIP(value, 0, 65535);
+        CHECK_ROUNDTRIP(value, 2, 1);
         value = -value;
-        CHECK_ROUNDTRIP(value, -32768, 32767);
+        CHECK_ROUNDTRIP(value, 2, 0);
     }
 
     for(size_t i = 0; i < 32 ; i++) {
         intmax_t value = (intmax_t)1 << i;
-        CHECK_ROUNDTRIP(value, 0, 4294967296UL);
+        CHECK_ROUNDTRIP(value, 4, 1);
         value = -value;
-        CHECK_ROUNDTRIP(value, -2147483648L, 2147483647L);
+        CHECK_ROUNDTRIP(value, 4, 0);
     }
 
     for(size_t i = 0; i < 8 * sizeof(intmax_t) ; i++) {
         intmax_t value = (intmax_t)1 << i;
-        CHECK_ROUNDTRIP(value, NoBound, NoBound);
+        CHECK_ROUNDTRIP(value, 8, 0);
         value = -value;
-        CHECK_ROUNDTRIP(value, NoBound, NoBound);
+        CHECK_ROUNDTRIP(value, 8, 0);
+    }
+
+    for(size_t i = 0; i < 8 * sizeof(intmax_t) ; i++) {
+        intmax_t value = (intmax_t)1 << i;
+        CHECK_ROUNDTRIP(value, 0, 0);
+        value = -value;
+        CHECK_ROUNDTRIP(value, 0, 0);
     }
 
 }