1
/* operator>> -- C++-style input of mpf_t.
3
Copyright 2001 Free Software Foundation, Inc.
5
This file is part of the GNU MP Library.
7
The GNU MP Library is free software; you can redistribute it and/or modify
8
it under the terms of the GNU Lesser General Public License as published by
9
the Free Software Foundation; either version 2.1 of the License, or (at your
10
option) any later version.
12
The GNU MP Library is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15
License for more details.
17
You should have received a copy of the GNU Lesser General Public License
18
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
MA 02111-1307, USA. */
29
#include <locale.h> /* for localeconv */
38
/* Perhaps the decimal point should be taken from the C++ <locale> stuff,
39
but that doesn't exist in g++ 2.95.x. In any case, using plain C
40
localeconv will ensure we parse exactly what mpf_set_str will expect, and
41
what the current operator<< implementation produces. */
44
operator>> (istream &i, mpf_ptr f)
51
i.get(c); // start reading
53
if (i.flags() & ios::skipws) // skip initial whitespace
54
while (isspace(c) && i.get(c))
57
if (c == '-' || c == '+') // sign
64
while (isspace(c) && i.get(c)) // skip whitespace
67
base = 10; // octal/hex floats currently unsupported
68
__gmp_istream_set_digits(s, i, c, ok, base); // read the number
71
const char *point = localeconv()->decimal_point;
72
if (c == *point) // radix point
84
__gmp_istream_set_digits(s, i, c, ok, base); // read the mantissa
87
if (c == '.') // radix point
91
__gmp_istream_set_digits(s, i, c, ok, base); // read the mantissa
95
if (ok && (c == 'e' || c == 'E' || c == '@')) // exponent
99
ok = false; // exponent is mandatory
101
if (c == '-' || c == '+') // sign
107
while (isspace(c) && i.get(c)) // skip whitespace
110
__gmp_istream_set_digits(s, i, c, ok, base); // read the exponent
113
if (i.good()) // last character read was non-numeric
115
else if (i.eof() && ok) // stopped just before eof
119
mpf_set_str(f, s.c_str(), base); // extract the number
123
i.setstate(ios::failbit); // read failed