Skip to content

[css-values-5] Make UA, not author, deal with floating point errors in random() #11864

Open
@fantasai

Description

@fantasai

Note that rounding issues might have an effect here: in random(100px, 200px, by 100px / 3) you’ll definitely get three possible values (100px, and approximately 133.33px and 166.67px),but whether 200px is possible depends on rounding precision. To be safe, you can put the maximum value slightly above where you expect the final step to land, like random(100px, 201px, by 100px / 3).

Issue: The author shouldn't need to think about floating point math errors. If the value is close enough to be functionally equivalent, the UA should just assume it matches.

Proposal: @tabatkins and I discussed this issue and suggest using 1% of the step value as "close enough", so if the final stepped value is within 1% of the step to the ending value (above or below), we use the end value as the final stepped value instead. An alternative we considered was to use some percentage of the canonical unit (1px/1deg/etc.).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions