Skip to content

[css-color-4] Sample color conversion code leads to NaN values #9477

Closed
@nex3

Description

@nex3

The sample code for converting from XYZ to OKLab involves taking the cube root of the result of multiplying the XYZ color by the XYZtoLMS matrix. This is undefined for negative numbers, and returns NaN, despite the fact that the XYZ color space is notionally unbounded and thus could very easily produce negative numbers.

This comes up even with fairly reasonable in-bounds colors. For example, lab(0.01% 35 1) is equivalent to xyz(0.008679770007260038 0.000011070564598794538 -0.0005206593067627204), which converts to LMS as [0.006751691618866409, 0.000022646971037596888, -0.00003832537822546193].

Should the LMS logic clamp channels so that they're 0 at minimum? Should it take the cube root of the absolute value and then match the sign afterwards?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closed as Question AnsweredUsed when the issue is more of a question than a problem, and it's been answered.css-color-4Current Work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions