Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346/* 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 either:89* the GNU Lesser General Public License as published by the Free10Software Foundation; either version 3 of the License, or (at your11option) any later version.1213or1415* the GNU General Public License as published by the Free Software16Foundation; either version 2 of the License, or (at your option) any17later version.1819or both in parallel, as here.2021The GNU MP Library is distributed in the hope that it will be useful, but22WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY23or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License24for more details.2526You should have received copies of the GNU General Public License and the27GNU Lesser General Public License along with the GNU MP Library. If not,28see https://www.gnu.org/licenses/. */2930#include <cctype>31#include <iostream>32#include <string>33#include <clocale> // for localeconv3435#include "gmp.h"36#include "gmp-impl.h"3738using namespace std;394041// For g++ libstdc++ parsing see num_get<chartype,initer>::_M_extract_float42// in include/bits/locale_facets.tcc.43//44// There are no plans to accept hex or octal floats, not unless the standard45// C++ library does so. Although such formats might be of use, it's46// considered more important to be compatible with what the normal47// operator>> does on "double"s etc.4849istream &50operator>> (istream &i, mpf_ptr f)51{52int base;53char c = 0;54string s;55bool ok = false;5657// C decimal point, as expected by mpf_set_str58const char *lconv_point = GMP_DECIMAL_POINT;5960// C++ decimal point61#if HAVE_STD__LOCALE62const locale& loc = i.getloc();63char point_char = use_facet< numpunct<char> >(loc).decimal_point();64#else65const char *point = lconv_point;66char point_char = *point;67#endif6869i.get(c); // start reading7071if (i.flags() & ios::skipws) // skip initial whitespace72{73// C++ isspace74#if HAVE_STD__LOCALE75const ctype<char>& ct = use_facet< ctype<char> >(loc);76#define cxx_isspace(c) (ct.is(ctype_base::space,(c)))77#else78#define cxx_isspace(c) isspace(c)79#endif8081while (cxx_isspace(c) && i.get(c))82;83}8485if (c == '-' || c == '+') // sign86{87if (c == '-')88s = "-";89i.get(c);90}9192base = 10;93__gmp_istream_set_digits(s, i, c, ok, base); // read the number9495// look for the C++ radix point, but put the C one in for mpf_set_str96if (c == point_char)97{98#if HAVE_STD__LOCALE99i.get(c);100#else // lconv point can be multi-char101for (;;)102{103i.get(c);104point++;105if (*point == '\0')106break;107if (c != *point)108goto fail;109}110#endif111s += lconv_point;112__gmp_istream_set_digits(s, i, c, ok, base); // read the mantissa113}114115if (ok && (c == 'e' || c == 'E')) // exponent116{117s += c;118i.get(c);119ok = false; // exponent is mandatory120121if (c == '-' || c == '+') // sign122{123s += c;124i.get(c);125}126127__gmp_istream_set_digits(s, i, c, ok, base); // read the exponent128}129130if (i.good()) // last character read was non-numeric131i.putback(c);132else if (i.eof() && ok) // stopped just before eof133i.clear(ios::eofbit);134135if (ok)136ASSERT_NOCARRY (mpf_set_str(f, s.c_str(), base)); // extract the number137else138{139fail:140i.setstate(ios::failbit); // read failed141}142143return i;144}145146147