Skip to content

Commit

Permalink
Fix evaluation of String(r, format) (#7924)
Browse files Browse the repository at this point in the history
- Prefix the usergiven format string with %.
  • Loading branch information
perost committed Sep 22, 2021
1 parent bcc8ddd commit 711560b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
1 change: 0 additions & 1 deletion .CI/compliance-newinst.failures
Expand Up @@ -113,7 +113,6 @@ ModelicaCompliance.Inheritance.Restrictions.BaseClassKindRecordModel
ModelicaCompliance.Inheritance.Restrictions.BaseClassKindRecordPackage
ModelicaCompliance.Inheritance.Restrictions.PrefixedClassWithComp
ModelicaCompliance.Inheritance.Restrictions.PrefixedClassWithExtends
ModelicaCompliance.Operators.Conversion.RealToString
ModelicaCompliance.Operators.Events.SampleIncorrect
ModelicaCompliance.Operators.Overloading.VectorizeConstructAndApply
ModelicaCompliance.Operators.Special.Cardinality
Expand Down
1 change: 0 additions & 1 deletion .CI/compliance.failures
Expand Up @@ -113,7 +113,6 @@ ModelicaCompliance.Inheritance.Restrictions.BaseClassKindRecordModel
ModelicaCompliance.Inheritance.Restrictions.BaseClassKindRecordPackage
ModelicaCompliance.Inheritance.Restrictions.PrefixedClassWithComp
ModelicaCompliance.Inheritance.Restrictions.PrefixedClassWithExtends
ModelicaCompliance.Operators.Conversion.RealToString
ModelicaCompliance.Operators.Events.SampleIncorrect
ModelicaCompliance.Operators.Overloading.VectorizeConstructAndApply
ModelicaCompliance.Operators.Special.Cardinality
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -2737,7 +2737,7 @@ algorithm

case {Expression.REAL(r), Expression.STRING(format)}
algorithm
str := System.sprintff(format, r);
str := System.sprintff("%" + format, r);
then
Expression.STRING(str);

Expand Down
2 changes: 1 addition & 1 deletion testsuite/flattening/modelica/scodeinst/CevalString1.mo
Expand Up @@ -15,7 +15,7 @@ model CevalString1
constant String s6 = String(E.three, leftJustified = false, minimumLength = 7);
constant String s7 = String(234.54);
constant String s8 = String(945.2, minimumLength = 10);
constant String s9 = String(0.3412341234123412, format = "%.10g");
constant String s9 = String(0.3412341234123412, format = ".10g");
constant String s10 = String(0.3412341234123412, significantDigits = 10);
end CevalString1;

Expand Down
8 changes: 4 additions & 4 deletions testsuite/flattening/modelica/scodeinst/FuncString.mo
Expand Up @@ -13,8 +13,8 @@ model FuncString
String s2 = String(E.one);
String s3 = String(true);
String s4 = String(1.0);
String s5 = String(1.0, significantDigits = 3);
String s6 = String(1.0, format = "-0.4g");
String s5 = String(1.234232, significantDigits = 3);
String s6 = String(1.2342342, format = "-0.4g");
String s7 = String(1, leftJustified = false, minimumLength = 3);
end FuncString;

Expand All @@ -24,8 +24,8 @@ end FuncString;
// String s2 = "one";
// String s3 = "true";
// String s4 = "1";
// String s5 = "1";
// String s6 = "-0.4g";
// String s5 = "1.23";
// String s6 = "1.234";
// String s7 = " 1";
// end FuncString;
// endResult

0 comments on commit 711560b

Please sign in to comment.