diff options
author | Matt Turner <[email protected]> | 2013-08-04 14:01:30 -0700 |
---|---|---|
committer | Matt Turner <[email protected]> | 2013-08-29 12:07:28 -0700 |
commit | 1ecfdba98a346c8bb05ad9403e3a6412574215f4 (patch) | |
tree | 32f3b23a594338f9eff821002807c39bb586b572 /src/glsl/ir_print_visitor.cpp | |
parent | 57cf5946ce7604aa42c78dbdc34c453f8b2a0b21 (diff) |
glsl: Add heuristics to print floating-point numbers better.
v2: Fix *.expected files to match.
Reviewed-by: Paul Berry <[email protected]>
Diffstat (limited to 'src/glsl/ir_print_visitor.cpp')
-rw-r--r-- | src/glsl/ir_print_visitor.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp index 541231a33c1..b5183108d6b 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); } |