Inconsistent rounding of the `repr` of `length`, `relative`, `fraction`, `ratio` and `angle` values
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 56.1k
- Forks
- 1.7k
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 22
Description
Description
Typst (tested on 0.9.0) seems to incorrectly round the repr of length, relative, fraction and ratio values between 1 and 1.035.
#repr(1.005pt + 1.005em) \
#repr(1.005%) \
#repr(1.005% + 1.005pt + 1.005em) \
#repr(1.005fr) \
#repr(1.015pt + 1.015em) \
#repr(1.015%) \
#repr(1.015% + 1.015pt + 1.015em) \
#repr(1.015fr) \
#repr(1.025pt + 1.025em) \
#repr(1.025%) \
#repr(1.025% + 1.025pt + 1.025em) \
#repr(1.025fr) \
#repr(1.035pt + 1.035em) \
#repr(1.035%) \
#repr(1.035% + 1.035pt + 1.035em) \
#repr(1.035fr) \
#repr(1.045pt + 1.045em) \
#repr(1.045%) \
#repr(1.045% + 1.045pt + 1.045em) \
#repr(1.045fr) \
1.036 rounds correctly:
#repr(1.036pt + 1.036em) \
#repr(1.036%) \
#repr(1.036% + 1.036pt + 1.036em) \
#repr(1.036fr) \
Compare that to the following, which simply changes the first digit from 1 to 2 for each component:
#repr(2.005pt + 2.005em) \
#repr(2.005%) \
#repr(2.005% + 2.005pt + 2.005em) \
#repr(2.005fr) \
#repr(2.015pt + 2.015em) \
#repr(2.015%) \
#repr(2.015% + 2.015pt + 2.015em) \
#repr(2.015fr) \
#repr(2.025pt + 2.025em) \
#repr(2.025%) \
#repr(2.025% + 2.025pt + 2.025em) \
#repr(2.025fr) \
#repr(2.035pt + 2.035em) \
#repr(2.035%) \
#repr(2.035% + 2.035pt + 2.035em) \
#repr(2.035fr) \
#repr(2.045pt + 2.045em) \
#repr(2.045%) \
#repr(2.045% + 2.045pt + 2.045em) \
#repr(2.045fr) \
As evident, em components are also not rounded.
I would argue that none of the components should be rounded, since repr (as stated in the documentation) is for debugging purposes. There's not much use for repr for debugging if it doesn't precisely represent the actual value. With the fields added by https://github.com/typst/typst/pull/790, you can, of course, work around this, but I think my point still stands.
EDIT: The issue is also present for angle.
Reproduction URL
No response
Operating system
Linux
Typst version
- I am using the latest version of Typst
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the listed #repr examples for length, relative, fraction, ratio, and angle values in Typst. Trace the repr formatting entry point and compare the behavior around 1.005–1.045 with the 1.036 and 2.x examples. Done means the affected values have consistent, documented rounding behavior, covered by regression tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100