[Mesa-dev] Using the 'f' suffix to create a float from an integer literal

Iago Toral Quiroga itoral at igalia.com
Wed Nov 19 03:47:51 PST 2014


I came across a GLSL test that checks that doing something like this in
a shader should fail:

float value = 1f;

However, this works fine in Mesa. Checking the spec I  see:

Floating-point constants are defined as follows.
           fractional-constant exponent-part(opt) floating-suffix(opt)
           digit-sequence exponent-part floating-suffix(opt)
           digit-sequence . digit-sequence
           digit-sequence .
           . digit-sequence
           e sign(opt) digit-sequence
           E sign(opt) digit-sequence
     sign: one of
           + -
           digit-sequence digit
     floating-suffix: one of
           f F

which suggests that the test is correct and Mesa has a bug. According to
the above rules, however, something like this is fine:

float f = 1e2f;

which I find kind of weird if the other case is not valid, so I wonder
if there is a bug in the spec or this is on purpose for some reason that
I am missing.

Then, to make matters worse, I read this in opengl.org wiki [1]:

"A numeric literal that uses a decimal is by default of type float​. To
create a float literal from an integer value, use the suffix f​ or F​ as
in C/C++."

which contradicts the spec and the test and is aligned with the current
way Mesa works.

So: does anyone know what version is right? Could this be a bug in the
spec? and if it is not, do we want to change the behavior to follow the
spec as it is now?


[1] https://www.opengl.org/wiki/Data_Type_%28GLSL%29

More information about the mesa-dev mailing list