GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* Auxiliary functions for C++-style input of GMP types.12Copyright 2001 Free Software Foundation, Inc.34This file is part of the GNU MP Library.56The GNU MP Library is free software; you can redistribute it and/or modify7it under the terms of the GNU Lesser General Public License as published by8the Free Software Foundation; either version 2.1 of the License, or (at your9option) any later version.1011The GNU MP Library is distributed in the hope that it will be useful, but12WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY13or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public14License for more details.1516You should have received a copy of the GNU Lesser General Public License17along with the GNU MP Library; see the file COPYING.LIB. If not, write to18the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,19MA 02110-1301, USA. */2021#include <cctype>22#include <iostream>23#include <string>24#include "gmp.h"25#include "gmp-impl.h"2627using namespace std;282930int31__gmp_istream_set_base (istream &i, char &c, bool &zero, bool &showbase)32{33int base;3435zero = showbase = false;36switch (i.flags() & ios::basefield)37{38case ios::dec:39base = 10;40break;41case ios::hex:42base = 16;43break;44case ios::oct:45base = 8;46break;47default:48showbase = true; // look for initial "0" or "0x" or "0X"49if (c == '0')50{51if (! i.get(c))52c = 0; // reset or we might loop indefinitely5354if (c == 'x' || c == 'X')55{56base = 16;57i.get(c);58}59else60{61base = 8;62zero = true; // if no other digit is read, the "0" counts63}64}65else66base = 10;67break;68}6970return base;71}7273void74__gmp_istream_set_digits (string &s, istream &i, char &c, bool &ok, int base)75{76switch (base)77{78case 10:79while (isdigit(c))80{81ok = true; // at least a valid digit was read82s += c;83if (! i.get(c))84break;85}86break;87case 8:88while (isdigit(c) && c != '8' && c != '9')89{90ok = true; // at least a valid digit was read91s += c;92if (! i.get(c))93break;94}95break;96case 16:97while (isxdigit(c))98{99ok = true; // at least a valid digit was read100s += c;101if (! i.get(c))102break;103}104break;105}106}107108109