57 if (as.
nelem() == 1) {
58 nom = strtol(s.c_str(), &endptr, 10);
59 if (endptr != s.c_str() + s.nelem())
60 throw std::runtime_error(
"Error parsing rational number");
62 }
else if (as.
nelem() == 2) {
63 nom = strtol(as[0].c_str(), &endptr, 10);
64 if (endptr != as[0].c_str() + as[0].
nelem())
65 throw std::runtime_error(
"Error parsing rational number nominator");
66 denom = strtol(as[1].c_str(), &endptr, 10);
67 if (endptr != as[1].c_str() + as[1].
nelem())
68 throw std::runtime_error(
"Error parsing rational number denominator");
71 throw std::runtime_error(
"Error parsing rational number");
72 }
catch (
const std::runtime_error& e) {
73 std::ostringstream os;
74 os <<
"Error parsing rational number: " << s << std::endl;
76 throw std::runtime_error(os.str());
85 auto len = s.length();
88 auto dot_pos = s.find(
".");
89 auto slash_pos = s.find(
"/");
92 }
else if (len > slash_pos) {
93 *
this =
Rational(std::stoi(s.substr(0, slash_pos)),
94 std::stoi(s.substr(slash_pos + 1, len)));