summaryrefslogtreecommitdiff
path: root/cxx
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2003-10-24 23:46:05 +0200
committerKevin Ryde <user42@zip.com.au>2003-10-24 23:46:05 +0200
commit264dcd9583e92f69a55fdcf745486f5cd7c94cc8 (patch)
tree33752fda0dec6425faa12da707a294e0256e59a5 /cxx
parent330eda03941bfdea0ccabb3a9df5776d846f1809 (diff)
downloadgmp-264dcd9583e92f69a55fdcf745486f5cd7c94cc8.tar.gz
* cxx/ismpq.cc: Rewrite using mpz input routines. Change to accept a
separate base indicator on numerator and denominator. Fix base indicator case where "123/0456" would stop at "123/0".
Diffstat (limited to 'cxx')
-rw-r--r--cxx/ismpq.cc75
1 files changed, 15 insertions, 60 deletions
diff --git a/cxx/ismpq.cc b/cxx/ismpq.cc
index d325e57ee..91dd1f46d 100644
--- a/cxx/ismpq.cc
+++ b/cxx/ismpq.cc
@@ -1,6 +1,6 @@
/* operator>> -- C++-style input of mpq_t.
-Copyright 2001, 2003 Free Software Foundation, Inc.
+Copyright 2003 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -31,73 +31,28 @@ using namespace std;
istream &
operator>> (istream &i, mpq_ptr q)
{
- int base;
- char c = 0;
- string s;
- bool ok = false, zero, showbase;
+ if (! (i >> mpq_numref(q)))
+ return i;
+ char c = 0;
i.get(c); // start reading
- if (i.flags() & ios::skipws) // skip initial whitespace
+ if (c == '/')
{
-#if HAVE_STD__LOCALE
- const ctype<char>& ct = use_facet< ctype<char> >(i.getloc());
-#define cxx_isspace(c) (ct.is(ctype_base::space,(c)))
-#else
-#define cxx_isspace(c) isspace(c)
-#endif
-
- while (cxx_isspace(c) && i.get(c))
- ;
- }
- if (c == '-' || c == '+') // sign
- {
- if (c == '-')
- s = "-";
+ // skip slash, read denominator
i.get(c);
+ return __gmpz_operator_in_nowhite (i, mpq_denref(q), c);
}
-
- base = __gmp_istream_set_base(i, c, zero, showbase); // select the base
- __gmp_istream_set_digits(s, i, c, ok, base); // read the numerator
-
- if (! ok && zero) // the only digit read was "0"
+ else
{
- base = 10;
- s += '0';
- ok = true;
+ // no denominator, set 1
+ q->_mp_den._mp_size = 1;
+ q->_mp_den._mp_d[0] = 1;
+ if (i.good())
+ i.putback(c);
+ else if (i.eof())
+ i.clear();
}
- if (c == '/') // there's a denominator
- {
- bool zero2 = false;
- int base2 = base;
-
- s += '/';
- ok = false; // denominator is mandatory
- i.get(c);
-
- if (showbase) // check base of denominator
- base2 = __gmp_istream_set_base(i, c, zero2, showbase);
-
- if (base2 == base || base2 == 10) // read the denominator
- __gmp_istream_set_digits(s, i, c, ok, base);
-
- if (! ok && zero2) // the only digit read was "0"
- { // denominator is 0, but that's your business
- s += '0';
- ok = true;
- }
- }
-
- if (i.good()) // last character read was non-numeric
- i.putback(c);
- else if (i.eof() && ok) // stopped just before eof
- i.clear();
-
- if (ok)
- mpq_set_str(q, s.c_str(), base); // extract the number
- else
- i.setstate(ios::failbit); // read failed
-
return i;
}