]> git.tdb.fi Git - libs/gl.git/commitdiff
Even better formatting of folded literals
authorMikko Rasa <tdb@tdb.fi>
Thu, 22 Apr 2021 10:57:22 +0000 (13:57 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 22 Apr 2021 10:57:22 +0000 (13:57 +0300)
A negative value does not consist entirely of digits yet may lack a
decimal point.  But a point must not be added after an exponent.

source/glsl/optimize.cpp

index ed20bb175dcc9277e1ff84e2e1a1734b2279668f..16e43a9e44c6d689a13f92f8655e0b258bb0d5e8 100644 (file)
@@ -646,8 +646,8 @@ void ConstantFolder::visit(RefPtr<Expression> &expr)
                literal->token = lexical_cast<string>(r_constant_value.value<unsigned>())+"u";
        else if(r_constant_value.check_type<float>())
        {
-               literal->token = lexical_cast<string>(r_constant_value.value<float>());
-               if(isnumrc(literal->token))
+               literal->token = lexical_cast<string>(r_constant_value.value<float>(), Fmt().precision(8));
+               if(literal->token.find('.')==string::npos && literal->token.find('e')==string::npos)
                        literal->token += ".0";
        }
        else