[Mesa-dev] [PATCH 08/15] glsl: Add heuristics to print floating-point numbers better.

Paul Berry stereotype441 at gmail.com
Fri Aug 23 08:57:30 PDT 2013


On 22 August 2013 16:08, Matt Turner <mattst88 at gmail.com> wrote:

> ---
>  src/glsl/ir_print_visitor.cpp | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp
> index 541231a..b518310 100644
> --- a/src/glsl/ir_print_visitor.cpp
> +++ b/src/glsl/ir_print_visitor.cpp
> @@ -406,7 +406,17 @@ void ir_print_visitor::visit(ir_constant *ir)
>          switch (ir->type->base_type) {
>          case GLSL_TYPE_UINT:  printf("%u", ir->value.u[i]); break;
>          case GLSL_TYPE_INT:   printf("%d", ir->value.i[i]); break;
> -        case GLSL_TYPE_FLOAT: printf("%f", ir->value.f[i]); break;
> +        case GLSL_TYPE_FLOAT:
> +            if (ir->value.f[i] == 0.0f)
> +               /* 0.0 == -0.0, so print with %f to get the proper sign. */
> +               printf("%.1f", ir->value.f[i]);
> +            else if (abs(ir->value.f[i]) < 0.000001f)
> +               printf("%a", ir->value.f[i]);
> +            else if (abs(ir->value.f[i]) > 1000000.0f)
> +               printf("%e", ir->value.f[i]);
> +            else
> +               printf("%f", ir->value.f[i]);
> +            break;
>          case GLSL_TYPE_BOOL:  printf("%d", ir->value.b[i]); break;
>          default: assert(0);
>          }
>

Unfortunately, this patch breaks "make check", because
src/glsl/tests/optimization-test does a strict character-by-character diff
between the expected and actual output of optimization passes (I'm not
thrilled that the optimization tests do this, but off hand I can't think of
a better way that wouldn't be a pain to implement).

I believe you can fix it by replacing "(0.000000)" with "(0.0)" in all the
*.expected files in src/glsl/tests/lower_jumps/.

With the "make check" issue fixed, this patch is:

Reviewed-by: Paul Berry <strereotype441 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20130823/02417ec2/attachment.html>


More information about the mesa-dev mailing list