Skip to content

Inconsistent rounding of the repr of length, relative, fraction, ratio and angle values #2836

@dixslyf

Description

@dixslyf

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) \

image

1.036 rounds correctly:

#repr(1.036pt + 1.036em) \
#repr(1.036%) \
#repr(1.036% + 1.036pt + 1.036em) \
#repr(1.036fr) \

image

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) \

image

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 #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingscriptingAbout Typst's coding capabilities

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions