Skip to content

Add Lerp to IFloatingPointIeee754 #81186

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

Merged
merged 4 commits into from
Jan 26, 2023
Merged

Conversation

tannergooding
Copy link
Member

This resolves #80044

@ghost
Copy link

ghost commented Jan 25, 2023

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned tannergooding Jan 25, 2023
@ghost
Copy link

ghost commented Jan 25, 2023

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

This resolves #80044

Author: tannergooding
Assignees: -
Labels:

area-System.Numerics, new-api-needs-documentation

Milestone: -

Copy link
Contributor

@dakersnar dakersnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Anything notably tricky that could use a triple check?

@tannergooding
Copy link
Member Author

LGTM. Anything notably tricky that could use a triple check?

Not really, this is a really straightforward API with a trivial implementation.

The biggest "gotcha" is ensuring that it is implemented as (value1 * (1.0f - amount)) + (value2 * amount) and not as value1 + ((value2 - value1) * amount)

The two algorithms are mathematically "equivalent" (assuming amount is between 0 and 1, inclusive). However, they produce different results for various edge cases when considering floating-point values and only the former is guaranteed to correctly return value2 when amount == 1.0f

@dakersnar
Copy link
Contributor

The floating-point-specific behavior for this functionality is not specified in the IEEE spec, correct? Given that, I assume we are just following common sense and industry standards when deciding how these edge cases are handled?

@tannergooding
Copy link
Member Author

Correct

@tannergooding tannergooding merged commit 26b58b9 into dotnet:main Jan 26, 2023
@tannergooding tannergooding deleted the lerp branch January 26, 2023 10:18
@ghost ghost locked as resolved and limited conversation to collaborators Feb 25, 2023
@jeffhandley jeffhandley added the blog-candidate Completed PRs that are candidate topics for blog post coverage label Mar 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Numerics blog-candidate Completed PRs that are candidate topics for blog post coverage new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: IFloatingPointIeee754<T>.Lerp
3 participants