[Mesa-dev] [PATCH 2/5] glsl: Extend s-expression parsing to handle infinity.
Paul Berry
stereotype441 at gmail.com
Fri Oct 28 11:25:18 PDT 2011
On 27 October 2011 20:13, Kenneth Graunke <kenneth at whitecape.org> wrote:
> On 10/26/2011 06:42 PM, Paul Berry wrote:
> > In order to implement the GLSL 1.30 isinf() function, it will be
> > necessary to be able to represent infinity in the GLSL IR s-expression
> > format. This patch extends the s-expression parser so that it treats
> > the string "#inf" as a floating point value representing positive
> > infinity.
> > ---
> > src/glsl/s_expression.cpp | 33 +++++++++++++++++++--------------
> > 1 files changed, 19 insertions(+), 14 deletions(-)
>
> Two kind of stupid comments:
>
> Scheme represents infinity as +inf.0 or -inf.0 and NaN as +nan.0. If
> you wanted to be more Scheme-like, you could do that (and also gain a
> representation of -infinity if you wanted...)
>
> Also...strtod() already accepts "INF"/"INFINITY" and "NAN" for these
> cases. Which actually kind of sucks because somebody could totally name
> their variables that (unlike #inf or +inf.0).
>
Interesting, I wasn't aware of that. According to
http://pubs.opengroup.org/onlinepubs/007904975/functions/strtod.html,
"+INFINITY" and "+INF" are also allowed as a representation of infinity;
likewise for "+NAN".
>
> That should be fixed someday. But there are a lot of things the reader
> can't do (like structs), so...not terribly important. It works well
> enough for now and we can always fix it when it actually matters.
>
Agreed. In particular, if we ever decide to use the s-expression IR
representation to support ARB_get_program_binary, we'll need to fix this.
I'll put a comment in the function as a reminder.
>
> So, I guess you've got a few options:
> 1. Keep patch as is (#inf)
> 2. Switch to +inf.0, -inf.0, +nan.0 to be like Scheme
> 3. Drop this patch and just use INFINITY in the built-in files.
>
Ok, I'm now favoring a fourth option:
4. drop this patch and use "+INF" in the built-in files.
That has the advantage that it can't be confused with a variable name.
I was going to push the patch series today, but I'm not in any rush. I'll
leave it open for another day in case anyone else wants to comment. If no
one comments by Monday I'll go with option 4.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20111028/dd7ebe51/attachment.htm>
More information about the mesa-dev
mailing list