diff --git a/libentcode/ectest.c b/libentcode/ectest.c
index 3f64288c01e451f793ec72170afb5c3a869684c6..18d42bf1d478127532f75c008f4b362aa53dbd13 100644
--- a/libentcode/ectest.c
+++ b/libentcode/ectest.c
@@ -73,11 +73,11 @@ int main(int _argc,char **_argv){
     }
     ec_probmod_clear(&mod);
   }
-  nbits=ec_enc_tell(&enc);
+  nbits=ec_enc_tellf(&enc,4);
   ec_enc_done(&enc);
   fprintf(stderr,
-   "Encoded %0.2lf bits of entropy to %li bits (%0.3lf%% wasted).\n",
-   entropy,nbits,100*(nbits-entropy)/nbits);
+   "Encoded %0.2lf bits of entropy to %0.2lf bits (%0.3lf%% wasted).\n",
+   entropy,ldexp(nbits,-4),100*(nbits-ldexp(entropy,4))/nbits);
   fprintf(stderr,"Packed to %li bytes.\n",(long)(buf.ptr-buf.buf));
   ec_byte_readinit(&buf,ec_byte_get_buffer(&buf),ec_byte_bytes(&buf));
   ec_dec_init(&dec,&buf);
diff --git a/libentcode/entenc.h b/libentcode/entenc.h
index 3179bcc2ded6fe25b67bdb3b581cbeba61934be2..61f89879e88780134d79b9827cc64f1b949fa80d 100644
--- a/libentcode/entenc.h
+++ b/libentcode/entenc.h
@@ -66,9 +66,18 @@ void ec_enc_uint64(ec_enc *_this,ec_uint64 _fl,ec_uint64 _ft);
 /*Returns the number of bits "used" by the encoded symbols so far.
   The actual number of bits may be larger, due to rounding to whole bytes, or
    smaller, due to trailing zeros that can be stripped.
-  Return: the number of bits.*/
+  Return: The number of bits.*/
 long ec_enc_tell(ec_enc *_this);
 
+/*Returns the number of bits "used" by the encoded symbols so far.
+  The actual number of bits may be larger, due to rounding to whole bytes, or
+   smaller, due to trailing zeros that can be stripped.
+  _b: The number of extra bits of precision to include.
+      At most 16 will be accurate.
+  Return: The number of bits scaled by 2**_b.
+          This will always be slightly larger than the exact value.*/
+long ec_enc_tellf(ec_enc *_this,int _b);
+
 /*Indicates that there are no more symbols to encode.
   All reamining output bytes are flushed to the output buffer.
   ec_enc_init() must be called before the encoder can be used again.*/
diff --git a/libentcode/mfrngenc.c b/libentcode/mfrngenc.c
index 5d222a9157db2b839c9fa278e9b584365d49a07e..5debf8adae5d47f67532f6c78a6af7b08b75e496 100644
--- a/libentcode/mfrngenc.c
+++ b/libentcode/mfrngenc.c
@@ -132,6 +132,31 @@ long ec_enc_tell(ec_enc *_this){
   return nbits;
 }
 
+long ec_enc_tellf(ec_enc *_this,int _b){
+  ec_uint32 r;
+  int       l;
+  long      nbits;
+  nbits=ec_byte_bytes(_this->buf)+(_this->rem>=0)+_this->ext<<3;
+  /*To handle the non-integral number of bits still left in the encoder state,
+     we compute the number of bits of low that must be encoded to ensure that
+     the value is inside the range for any possible subsequent bits.
+    Note that this is subtly different than the actual value we would end the
+     stream with, which tries to make as many of the trailing bits zeros as
+     possible.*/
+  nbits+=EC_CODE_BITS;
+  nbits<<=_b;
+  l=EC_ILOG(_this->rng);
+  r=_this->rng>>l-16;
+  while(_b-->0){
+    int b;
+    r=r*r>>15;
+    b=(int)(r>>16);
+    l=l<<1|b;
+    r>>=b;
+  }
+  return nbits-l;
+}
+
 void ec_enc_done(ec_enc *_this){
   /*We compute the integer in the current interval that has the largest number
      of trailing zeros, and write that to the stream.
diff --git a/libentcode/rangeenc.c b/libentcode/rangeenc.c
index 5833da6479256e33a6b8f422b4d866b4e85d1a8a..8d3eef3b3c51a074cfc281590bab537a5f54c198 100644
--- a/libentcode/rangeenc.c
+++ b/libentcode/rangeenc.c
@@ -104,6 +104,31 @@ long ec_enc_tell(ec_enc *_this){
   return nbits;
 }
 
+long ec_enc_tellf(ec_enc *_this,int _b){
+  ec_uint32 r;
+  int       l;
+  long      nbits;
+  nbits=ec_byte_bytes(_this->buf)+(_this->rem>=0)+_this->ext<<3;
+  /*To handle the non-integral number of bits still left in the encoder state,
+     we compute the number of bits of low that must be encoded to ensure that
+     the value is inside the range for any possible subsequent bits.
+    Note that this is subtly different than the actual value we would end the
+     stream with, which tries to make as many of the trailing bits zeros as
+     possible.*/
+  nbits+=EC_CODE_BITS;
+  nbits<<=_b;
+  l=EC_ILOG(_this->rng);
+  r=_this->rng>>l-16;
+  while(_b-->0){
+    int b;
+    r=r*r>>15;
+    b=(int)(r>>16);
+    l=l<<1|b;
+    r>>=b;
+  }
+  return nbits-l;
+}
+
 void ec_enc_done(ec_enc *_this){
   /*We compute the integer in the current interval that has the largest number
      of trailing zeros, and write that to the stream.