GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* operator>> -- C++-style input of mpf_t.12Copyright 2001, 2003 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 <clocale> // for localeconv2526#include "gmp.h"27#include "gmp-impl.h"2829using namespace std;303132// For g++ libstdc++ parsing see num_get<chartype,initer>::_M_extract_float33// in include/bits/locale_facets.tcc.34//35// There are no plans to accept hex or octal floats, not unless the standard36// C++ library does so. Although such formats might be of use, it's37// considered more important to be compatible with what the normal38// operator>> does on "double"s etc.3940istream &41operator>> (istream &i, mpf_ptr f)42{43int base;44char c = 0;45string s;46bool ok = false;4748// C decimal point, as expected by mpf_set_str49const char *lconv_point = localeconv()->decimal_point;5051// C++ decimal point52#if HAVE_STD__LOCALE53const locale& loc = i.getloc();54char point_char = use_facet< numpunct<char> >(loc).decimal_point();55#else56const char *point = lconv_point;57char point_char = *point;58#endif5960i.get(c); // start reading6162if (i.flags() & ios::skipws) // skip initial whitespace63{64// C++ isspace65#if HAVE_STD__LOCALE66const ctype<char>& ct = use_facet< ctype<char> >(loc);67#define cxx_isspace(c) (ct.is(ctype_base::space,(c)))68#else69#define cxx_isspace(c) isspace(c)70#endif7172while (cxx_isspace(c) && i.get(c))73;74}7576if (c == '-' || c == '+') // sign77{78if (c == '-')79s = "-";80i.get(c);81}8283base = 10;84__gmp_istream_set_digits(s, i, c, ok, base); // read the number8586// look for the C++ radix point, but put the C one in for mpf_set_str87if (c == point_char)88{89#if HAVE_STD__LOCALE90i.get(c);91#else // lconv point can be multi-char92for (;;)93{94i.get(c);95point++;96if (*point == '\0')97break;98if (c != *point)99goto fail;100}101#endif102s += lconv_point;103__gmp_istream_set_digits(s, i, c, ok, base); // read the mantissa104}105106if (ok && (c == 'e' || c == 'E')) // exponent107{108s += c;109i.get(c);110ok = false; // exponent is mandatory111112if (c == '-' || c == '+') // sign113{114s += c;115i.get(c);116}117118__gmp_istream_set_digits(s, i, c, ok, base); // read the exponent119}120121if (i.good()) // last character read was non-numeric122i.putback(c);123else if (i.eof() && ok) // stopped just before eof124i.clear();125126if (ok)127ASSERT_NOCARRY (mpf_set_str(f, s.c_str(), base)); // extract the number128else129{130fail:131i.setstate(ios::failbit); // read failed132}133134return i;135}136137138