Skip to content

Commit

Permalink
Merge pull request #1212 from agarny/issue1211
Browse files Browse the repository at this point in the history
Analyser: improve the reporting of unit-related issues with the pow() function
  • Loading branch information
agarny authored Mar 27, 2024
2 parents 42ee12c + 6c8fb10 commit a788603
Show file tree
Hide file tree
Showing 8 changed files with 1,441 additions and 84 deletions.
385 changes: 306 additions & 79 deletions src/analyser.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ std::string doPrintAstAsTree(const AnalyserEquationAstPtr &ast)
}

std::string doPrintAstAsTree(const AnalyserEquationAstPtr &ast,
AnalyserEquationAstTrunk *prevTrunk, bool isLeft)
AnalyserEquationAstTrunk *prevTrunk, bool isLeft)
{
if (ast == nullptr) {
return {};
Expand Down
3 changes: 2 additions & 1 deletion src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ struct Debug

void printAnalyserModelEquations(const AnalyserModelPtr &model);
void printAnalyserModelVariables(const AnalyserModelPtr &model);
void printAst(const AnalyserEquationAstPtr &ast);
void printAstAsTree(const AnalyserEquationAstPtr &ast);
void printAstAsCode(const AnalyserEquationAstPtr &ast);
void printComponentMap(const ComponentMap &map);
void printConnectionMap(const ConnectionMap &map);
void printEquivalenceMap(const EquivalenceMap &map);
Expand Down
2 changes: 1 addition & 1 deletion src/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ std::string Generator::GeneratorImpl::generateMethodBodyCode(const std::string &
methodBody;
}

std::string Generator::GeneratorImpl::generateDoubleCode(const std::string &value) const
std::string generateDoubleCode(const std::string &value)
{
if (value.find('.') != std::string::npos) {
return value;
Expand Down
3 changes: 2 additions & 1 deletion src/generator_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ limitations under the License.

namespace libcellml {

std::string generateDoubleCode(const std::string &value);

/**
* @brief The Generator::GeneratorImpl struct.
*
Expand Down Expand Up @@ -109,7 +111,6 @@ struct Generator::GeneratorImpl

std::string generateMethodBodyCode(const std::string &methodBody) const;

std::string generateDoubleCode(const std::string &value) const;
std::string generateDoubleOrConstantVariableNameCode(const VariablePtr &variable) const;
std::string generateVariableNameCode(const VariablePtr &variable,
bool state = true) const;
Expand Down
5 changes: 5 additions & 0 deletions src/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ Strings split(const std::string &content, const std::string &delimiter)

std::string convertToString(double value, bool fullPrecision)
{
if (std::isnan(value)) {
// Always return "nan" whether we are dealing with +NAN or -NAN. This is to ensure that
// the string representation of a NAN is consistent across compilers.
return "nan";
}
std::ostringstream strs;
if (fullPrecision) {
strs << std::setprecision(std::numeric_limits<double>::digits10) << value;
Expand Down
85 changes: 84 additions & 1 deletion tests/analyser/analyserunits.cpp

Large diffs are not rendered by default.

Loading

0 comments on commit a788603

Please sign in to comment.