Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add support for Fortran D-exponent notation
  • Loading branch information
Amitjoiya committed Nov 28, 2025
commit 3709938d04adfd19ead719198efe710579048147
2 changes: 1 addition & 1 deletion src/CalcManager/CEngine/scidisp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace CalcEngine;
constexpr int MAX_EXPONENT = 4;
constexpr uint32_t MAX_GROUPING_SIZE = 16;
constexpr wstring_view c_decPreSepStr = L"[+-]?(\\d*)[";
constexpr wstring_view c_decPostSepStr = L"]?(\\d*)(?:e[+-]?(\\d*))?$";
constexpr wstring_view c_decPostSepStr = L"]?(\\d*)(?:[eEdD][+-]?(\\d*))?$";

/****************************************************************************\
* void DisplayNum(void)
Expand Down
29 changes: 29 additions & 0 deletions src/CalculatorUnitTests/CalcEngineTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <CppUnitTest.h>

#include "CalcViewModel/Common/EngineResourceProvider.h"
#include "ratpak.h"

using namespace std;
using namespace CalculatorApp;
Expand Down Expand Up @@ -235,6 +236,34 @@ namespace CalculatorEngineTests
L"Verify expanded form multigroup non-repeating grouping.");
}

TEST_METHOD(TestFortranDNotationParsing)
{
// Parse a Fortran-style D exponent and verify numeric value
PNUMBER pnum = StringToNumber(L"1.073092093321713D-002", 10, 17);
VERIFY_IS_NOT_NULL(pnum);
std::wstring s = NumberToString(pnum, NumberFormat::Float, 10, 17);
double actual = std::stod(s);
double expected = 1.073092093321713e-2;
Assert::AreEqual(expected, actual, 1e-15, L"D-notation should parse to correct numeric value");
destroynum(pnum);

// Verify equivalence with E-notation
PNUMBER pnumE = StringToNumber(L"1.073092093321713E-002", 10, 17);
VERIFY_IS_NOT_NULL(pnumE);
std::wstring sE = NumberToString(pnumE, NumberFormat::Float, 10, 17);
double actualE = std::stod(sE);
Assert::AreEqual(expected, actualE, 1e-15, L"E-notation should parse to same numeric value");
destroynum(pnumE);

// Also test compact form like 5D5
PNUMBER pnum2 = StringToNumber(L"5D5", 10, 17);
VERIFY_IS_NOT_NULL(pnum2);
std::wstring s2 = NumberToString(pnum2, NumberFormat::Float, 10, 17);
double actual2 = std::stod(s2);
Assert::AreEqual(5e5, actual2, 1e-9, L"5D5 should parse as 5e5");
destroynum(pnum2);
}

private:
unique_ptr<CCalcEngine> m_calcEngine;
shared_ptr<IResourceProvider> m_resourceProvider;
Expand Down