X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/d3409d5ecf2492cff862616de72a580d1a8e8dc0..d4bb7fded5f9a4b0db99f82e88f22effe94f2ff7:/mptext.h diff --git a/mptext.h b/mptext.h index 667c098..dade3cf 100644 --- a/mptext.h +++ b/mptext.h @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: mptext.h,v 1.1 1999/11/17 18:02:16 mdw Exp $ + * $Id$ * * Textual representation of multiprecision numbers * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,28 +15,20 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: mptext.h,v $ - * Revision 1.1 1999/11/17 18:02:16 mdw - * New multiprecision integer arithmetic suite. - * - */ - -#ifndef MPTEXT_H -#define MPTEXT_H +#ifndef CATACOMB_MPTEXT_H +#define CATACOMB_MPTEXT_H #ifdef __cplusplus extern "C" { @@ -44,7 +36,7 @@ /*----- Header files ------------------------------------------------------*/ -#ifndef MP_H +#ifndef CATACOMB_MP_H # include "mp.h" #endif @@ -53,7 +45,7 @@ typedef struct mptext_ops { int (*get)(void */*p*/); void (*unget)(int /*ch*/, void */*p*/); - int (*put)(char */*s*/, size_t /*len*/, void */*p*/); + int (*put)(const char */*s*/, size_t /*len*/, void */*p*/); } mptext_ops; /*----- Functions provided ------------------------------------------------*/ @@ -94,6 +86,20 @@ extern mp *mp_read(mp */*m*/, int /*radix*/, extern int mp_write(mp */*m*/, int /*radix*/, const mptext_ops */*ops*/, void */*p*/); +/* --- @mptext_len@ --- * + * + * Arguments: @mp *x@ = number to work on + * @int r@ = radix the number will be expressed in + * + * Returns: The number of digits needed to represent the number in the + * given base. This will not include space for a leading sign + * (use @MP_NEGP@ to check that, or just add one on for luck); + * neither will it add space for a terminating null. In general + * the answer will be an overestimate. + */ + +extern size_t mptext_len(mp */*x*/, int /*r*/); + /*----- File I/O ----------------------------------------------------------*/ #include @@ -110,6 +116,26 @@ extern const mptext_ops mptext_fileops; extern mp *mp_readfile(mp */*m*/, FILE */*fp*/, int /*radix*/); extern int mp_writefile(mp */*m*/, FILE */*fp*/, int /*radix*/); +#define MP_DOFPRINTFR(fp, args, m, r) do { \ + fprintf args; \ + if (m) \ + mp_writefile(m, fp, r); \ + else \ + fputs("", fp); \ + fputc('\n', fp); \ +} while (0) + +#define MP_DOFPRINTR(fp, name, m, r) \ + MP_DOFPRINTFR(fp, (fp, "%s = ", name), m, r) + +#define MP_PRINT(name, m) MP_DOFPRINTR(stdout, name, m, 10) +#define MP_EPRINT(name, m) MP_DOFPRINTR(stderr, name, m, 10) +#define MP_PRINTX(name, m) MP_DOFPRINTR(stdout, name, m, 16) +#define MP_EPRINTX(name, m) MP_DOFPRINTR(stderr, name, m, 16) + +#define MP_FPRINTF(fp, args, m) MP_DOFPRINTFR(fp, args, m, 10) +#define MP_FPRINTFX(fp, args, m) MP_DOFPRINTFR(fp, args, m, 16) + /*----- String I/O --------------------------------------------------------*/ /* --- Context format --- */