Skip to content

Commit ca3db06

Browse files
committed
Added note that mp_radix_size_overestimate is similar in behavior to GMP's mpz_sizeinbase
1 parent f330340 commit ca3db06

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

bn_mp_radix_size_overestimate.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
/* returns size of ASCII representation */
1212

1313
/*
14-
Overestimate the amount of memory needed for the number-to-string conversions.
15-
The results for powers-of-two are exact but it will overestimate the actual
16-
amount by up to 1 character for all other bases with the exception of MP_16BIT
17-
where the overestimate is up to to 2 characters for all those other bases if
18-
the "int" type has more than 16 bits.
14+
15+
Behaves like the function mp(n|z)_sizeinbase of GMP for all digit-sizes except MP_8BIT
16+
and MP_16BIT (if the "int" for MP_16BIT has more than 16 bits) where it can overshoot by two.
17+
The results for bases that are powers-of-two are exact.
1918
*/
2019

2120
/*
@@ -104,7 +103,7 @@ static const mp_word logbases_low[65] = {
104103
638097011ul, 1073048670ul, 1651143338ul, 3473298766ul, 0ul
105104
};
106105

107-
/* TODO: This assumes the type "long long" exists. If it doesn't use the tables for MP_16BIT */
106+
/* TODO: This assumes the type "long long" exists. If it doesn't: use the tables for MP_16BIT */
108107
#elif ( (defined MP_28BIT) || (defined MP_31BIT) || (defined MP_32BIT) || (defined MP_64BIT) )
109108
#define LTM_RADIX_SIZE_SCALE 61
110109
#ifdef MP_64BIT

doc/bn.tex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,11 +2118,13 @@ \subsection{To ASCII}
21182118
This stores in ``size'' the exact number of characters (including space for the NUL terminator) required. Upon error this function returns an error code and ``size'' will be zero. It uses \texttt{mp\_ilogb} to compute the size in O(log n) with quite a large overhead. This function is deprecated in favor of
21192119
\texttt{mp\_radix\_sizeinbase} described below. If the exact size is still required after the removal of this function use \texttt{mp\_ilogb} directly.
21202120
2121-
\index{mp\_radix\_sizeinbase}
2121+
\index{mp\_radix\_overestimate}
21222122
\begin{alltt}
2123-
int mp_radix_sizeinbase (mp_int * a, int radix, int *size)
2123+
int mp_radix_size_overestimate (mp_int * a, int radix, int *size)
21242124
\end{alltt}
2125-
This stores in ``size'' the number of characters (including space for the NUL terminator) required. Upon error this function returns an error code and ``size'' will be zero. This function can overshoot by one (two in case of \texttt{MP\_8BIT}). It uses tables to compute the result in O(1) with quite a small overhead.
2125+
This stores in ``size'' the number of characters (including space for the NUL terminator) required. Upon error this function returns an error code and ``size'' will be zero. This function can overshoot by one (two in case of \texttt{MP\_8BIT} and also for \texttt{MP\_16BIT} if the type \texttt{int} has more than 16 bits). The results for bases that are powers-of-two are exact. It uses tables to compute the result in O(1) with quite a small overhead.
2126+
2127+
The behavior is similar to the behavior of the function \texttt{mpn\_sizeinbase} in GMP for \texttt{MP\_32BIT}, and \texttt{MP\_64BIT}.
21262128
21272129
If \texttt{LTM\_NO\_FILE} is not defined a function to write to a file is also available.
21282130
\index{mp\_fwrite}

tommath.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,11 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, int radix) MP_WUR;
713713

714714
/* exact but slow O(n^2)*/
715715
mp_err mp_radix_size(const mp_int *a, int radix, int *size) MP_WUR;
716-
/* can overshoot by one or two characters but is O(1) (table based with a very small overhead) */
716+
/*
717+
Can overshoot by one or two characters but is O(1) (table based with a very small overhead)
718+
Behaves like the function mp(n|z)_sizeinbase of GMP for all digit-sizes except MP_8BIT
719+
and MP_16BIT (if the "int" for MP_16BIT has more than 16 bits) where it can overshoot by two.
720+
*/
717721
mp_err mp_radix_size_overestimate(const mp_int *a, const int base, int *size) MP_WUR;
718722
#ifndef MP_NO_FILE
719723
mp_err mp_fread(mp_int *a, int radix, FILE *stream) MP_WUR;

0 commit comments

Comments
 (0)