diff options
| author | ReallyCrin <137194442+ReallyCrin@users.noreply.github.com> | 2026-11-23 13:30:44 -0800 |
|---|---|---|
| committer | ReallyCrin <137194442+ReallyCrin@users.noreply.github.com> | 2026-11-23 13:30:44 -0800 |
| commit | 9a0a1a2d5fe4e7f0786cf0d34564249f1fede278 (patch) | |
| tree | 46597851c45c0a2fec90a21626b856591b3b566d /scripts | |
| parent | 5d74c272363f2703265d44e6aaab1a1df8ddfaf3 (diff) | |
Preserve exact integral decimal counters in shader statistics
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/shader_stats.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/scripts/shader_stats.py b/scripts/shader_stats.py index fb95a1843..34b61cd8a 100644 --- a/scripts/shader_stats.py +++ b/scripts/shader_stats.py | |||
| @@ -24,6 +24,7 @@ import os | |||
| 24 | import statistics | 24 | import statistics |
| 25 | import sys | 25 | import sys |
| 26 | from collections import defaultdict | 26 | from collections import defaultdict |
| 27 | from decimal import Decimal, InvalidOperation | ||
| 27 | 28 | ||
| 28 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tools")) | 29 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tools")) |
| 29 | import shader_ir # noqa: E402 | 30 | import shader_ir # noqa: E402 |
| @@ -81,17 +82,21 @@ def load_stats(path): | |||
| 81 | 82 | ||
| 82 | def number(raw): | 83 | def number(raw): |
| 83 | """The exact int, or else the finite float, a raw value holds; None if it is missing or not such a number.""" | 84 | """The exact int, or else the finite float, a raw value holds; None if it is missing or not such a number.""" |
| 84 | if raw is None: | 85 | try: |
| 86 | value = float(raw) | ||
| 87 | except (TypeError, ValueError, OverflowError): | ||
| 88 | return None | ||
| 89 | if not math.isfinite(value): | ||
| 85 | return None | 90 | return None |
| 86 | for parse in (int, float): | 91 | if value.is_integer(): |
| 92 | # Beyond 2**53, converting the rounded float back to int can change the counter. | ||
| 87 | try: | 93 | try: |
| 88 | value = parse(raw) | 94 | exact = Decimal(raw) |
| 89 | if not math.isfinite(value): | 95 | except InvalidOperation: |
| 90 | return None | 96 | return value |
| 91 | return int(value) if isinstance(value, float) and value.is_integer() else value | 97 | if exact == exact.to_integral_value(): |
| 92 | except (TypeError, ValueError, OverflowError): | 98 | return int(exact) |
| 93 | pass | 99 | return value |
| 94 | return None | ||
| 95 | 100 | ||
| 96 | 101 | ||
| 97 | def shader_row(name, stage, st, src): | 102 | def shader_row(name, stage, st, src): |