fix float literals in C++ Pistache codegen (#11483)

This commit is contained in:
Julian G 2022-02-07 05:21:11 +01:00 committed by GitHub
parent 9f5422d688
commit 9e1972bb1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -408,7 +408,15 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
} else if (ModelUtils.isNumberSchema(p)) { } else if (ModelUtils.isNumberSchema(p)) {
if (ModelUtils.isFloatSchema(p)) { // float if (ModelUtils.isFloatSchema(p)) { // float
if (p.getDefault() != null) { if (p.getDefault() != null) {
return p.getDefault().toString() + "f"; // We have to ensure that our default value has a decimal point,
// because in C++ the 'f' suffix is not valid on integer literals
// i.e. 374.0f is a valid float but 374 isn't.
String defaultStr = p.getDefault().toString();
if (defaultStr.indexOf('.') < 0) {
return defaultStr + ".0f";
} else {
return defaultStr + "f";
}
} else { } else {
return "0.0f"; return "0.0f";
} }