]> git.tdb.fi Git - libs/gl.git/commitdiff
Make sure folded float constants appear as correct type
authorMikko Rasa <tdb@tdb.fi>
Tue, 20 Apr 2021 15:15:08 +0000 (18:15 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 20 Apr 2021 15:17:12 +0000 (18:17 +0300)
If the value has no fractional part, the default conversion will not
add a decimal point.

source/glsl/optimize.cpp

index 63dfcb5c2823758dc054f92cb4d1960650e05d44..044dd4e5a29ef1eefde6985b5c4798b93cf239fd 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/core/raii.h>
 #include <msp/strings/format.h>
+#include <msp/strings/utils.h>
 #include "optimize.h"
 #include "reflect.h"
 
@@ -617,7 +618,11 @@ void ConstantFolder::visit(RefPtr<Expression> &expr)
        else if(r_constant_value.check_type<int>())
                literal->token = lexical_cast<string>(r_constant_value.value<int>());
        else if(r_constant_value.check_type<float>())
+       {
                literal->token = lexical_cast<string>(r_constant_value.value<float>());
+               if(isnumrc(literal->token))
+                       literal->token += ".0";
+       }
        else
        {
                r_constant = false;