Skip to content

Harden linear_to_gamma() function? #1202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hollasch opened this issue Aug 11, 2023 · 0 comments · Fixed by #1211
Closed

Harden linear_to_gamma() function? #1202

hollasch opened this issue Aug 11, 2023 · 0 comments · Fixed by #1211
Assignees
Milestone

Comments

@hollasch
Copy link
Collaborator

We currently have the following implementation:

inline double linear_to_gamma(double linear_component)
{
    return sqrt(linear_component);
}

This will barf on negative values, returning NaN. Should we harden this like so?

inline double linear_to_gamma(double linear_component)
{
    if (linear_component < 0)
        return 0;

    return sqrt(linear_component);
}

or

inline double linear_to_gamma(double linear_component)
{
    return sqrt(fmax(0, linear_component));
}
@hollasch hollasch added this to the v4.0.0 milestone Aug 11, 2023
hollasch added a commit that referenced this issue Aug 13, 2023
Without this hardening, we will return NaNs for negative inputs, which
can happen from time to time.

I also ran across fmin/fmax in one implementation, which we never
commented on in the books. Added an explanation for these two functions
for readers unfamiliar with C++.

Resolves #1202
hollasch added a commit that referenced this issue Aug 16, 2023
Without this hardening, we will return NaNs for negative inputs, which
can happen from time to time.

I also ran across fmin/fmax in one implementation, which we never
commented on in the books. Added an explanation for these two functions
for readers unfamiliar with C++.

Resolves #1202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants