Keep the exponent digit when formatting floats with a zero exponent (#1543)

The float rewrite strips leading zeros and plus signs from the exponent,
so a float whose exponent is zero loses it entirely: `x = 1.5e0`,
`1.5e+0` and `1.0E00` are written back as `1.5e` and `1.0e`, which is no
longer valid Starlark.

I keep a single `0` when the exponent has digits but all of them are
zeros. A float with no exponent digits at all (`1.5e`) was already
invalid, and is now left as written instead of being rewritten.

The new cases in `build/testdata/003` cover `1.5e0`, `1.5e+0`, `1.0E00`
and `.5e+000`. I also compared the old and new output over a few hundred
combinations of mantissa, `e`/`E`, sign and exponent: only zero
exponents and the digitless ones changed.
3 files changed
tree: 0af1427490573460578d5da26074d9d43c33db4d
  1. .bazelci/
  2. .github/
  3. api_proto/
  4. build/
  5. build_proto/
  6. buildifier/
  7. buildozer/
  8. bzlenv/
  9. config/
  10. convertast/
  11. deps_proto/
  12. differ/
  13. edit/
  14. extra_actions_base_proto/
  15. file/
  16. generatetables/
  17. labels/
  18. lang/
  19. release/
  20. tables/
  21. testutils/
  22. unused_deps/
  23. warn/
  24. wspace/
  25. .bazelrc
  26. .bazelversion
  27. .gitignore
  28. .mailmap
  29. .pre-commit-config.yaml
  30. AGENTS.md
  31. BUILD.bazel
  32. CODEOWNERS
  33. CONTRIBUTING.md
  34. CONTRIBUTORS
  35. go.mod
  36. go.sum
  37. launcher.js
  38. LICENSE
  39. MODULE.bazel
  40. README.md
  41. renovate.json
  42. status.py
  43. update_generated.sh
  44. WARNINGS.md
  45. WORKSPACE
  46. WORKSPACE.bzlmod
README.md

Buildtools for bazel

This repository contains developer tools for working with Google's bazel buildtool.

Build status

Setup

See instructions in each tool's directory.