From 7d492b258075aa7423c8e53b744f9c48ea69b4dc Mon Sep 17 00:00:00 2001 From: "Maxie D. Schmidt" Date: Wed, 7 Oct 2020 21:07:30 -0400 Subject: [PATCH 1/2] Adding this recent commit for a proposed bug fix to issue #4 for the purposes of modular PRs --- src/pmfe_types.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pmfe_types.cc b/src/pmfe_types.cc index de66ce55..37c36e1f 100644 --- a/src/pmfe_types.cc +++ b/src/pmfe_types.cc @@ -144,7 +144,16 @@ namespace pmfe { theint = abs(theint); // Carve out the fractional part. Surprisingly fiddly! - int fracdenom = pow(10, fracpart.length()); + // Handle a corner case where the fractional part is all zeros: + int fracdenom = 1; + unsigned int lastNonZeroPos = fracpart.find_last_of("0"); + if(lastNonZeroPos != std::string::npos) { + while(lastNonZeroPos != std::string::npos) { + fracpart = fracpart.substr(0, lastNonZeroPos); + lastNonZeroPos = fracpart.find_last_of("0"); + } + fracdenom = pow(10, fracpart.length()); + } Integer fracval (fracpart, 10); Rational thefrac (fracval, fracdenom); thefrac.canonicalize(); From 375a2b992e8f0a1537ed7be25604907574f736d9 Mon Sep 17 00:00:00 2001 From: "Maxie D. Schmidt" Date: Sat, 24 Oct 2020 04:43:17 -0400 Subject: [PATCH 2/2] Fixing issue #12 --- src/pmfe_types.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pmfe_types.cc b/src/pmfe_types.cc index 37c36e1f..62f16b73 100644 --- a/src/pmfe_types.cc +++ b/src/pmfe_types.cc @@ -137,7 +137,7 @@ namespace pmfe { bool negative = (word.find('-') != std::string::npos); if (decimalpoint != std::string::npos) { std::string intpart = word.substr(0, decimalpoint); - std::string fracpart = word.substr(decimalpoint+1); + std::string fracpart = word.substr(decimalpoint + 1); if (intpart == "") intpart = "0"; Integer theint (intpart, 10); @@ -146,13 +146,18 @@ namespace pmfe { // Carve out the fractional part. Surprisingly fiddly! // Handle a corner case where the fractional part is all zeros: int fracdenom = 1; - unsigned int lastNonZeroPos = fracpart.find_last_of("0"); - if(lastNonZeroPos != std::string::npos) { - while(lastNonZeroPos != std::string::npos) { - fracpart = fracpart.substr(0, lastNonZeroPos); - lastNonZeroPos = fracpart.find_last_of("0"); + int lastNonZeroPos = fracpart.find_last_of("0"); + while(lastNonZeroPos + 1 == fracpart.length() && lastNonZeroPos != std::string::npos) { + if(lastNonZeroPos == 0) { + fracpart = ""; + break; } - fracdenom = pow(10, fracpart.length()); + fracpart = fracpart.substr(0, lastNonZeroPos); + lastNonZeroPos = fracpart.find_last_of("0"); + } + fracdenom = pow(10, fracpart.length()); + if(fracpart == "") { + fracpart = "0"; } Integer fracval (fracpart, 10); Rational thefrac (fracval, fracdenom); @@ -167,7 +172,7 @@ namespace pmfe { result.canonicalize(); return result; }; - + RNASequence::RNASequence(const std::string& seq): seq_txt(seq) {