Skip to content
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

Way to indicate out of range? #2

Closed
chmorgan opened this issue Oct 14, 2019 · 5 comments
Closed

Way to indicate out of range? #2

chmorgan opened this issue Oct 14, 2019 · 5 comments

Comments

@chmorgan
Copy link
Contributor

Would a pull request to modify At() to return (float64, error) be accepted? In my use case I'd prefer not to rely on a magic value of 0 to indicate not found but would propose instead we returned something like 0, fmt.Errorf("value out of range") so the user could decide how to handle those cases?

@sgreben
Copy link
Owner

sgreben commented Oct 14, 2019

Hey, thanks for getting in touch! Personally I'd prefer keeping the signature for At as-is. Open to discussion though :) Would something like func (f Function) IsInterpolatedAt(x float64) bool perhaps also cover your use-case? So you could then do

if !f.IsInterpolatedAt(x) {
   // x is not within domain X, f.At(x) is guaranteed to be zero
   return
}
//  x is within domain X, f.At(x) might be non-zero

I actually find it useful that the function is well-defined outside the X domain - this way it can be used wherever a func (float)float is expected.

@chmorgan
Copy link
Contributor Author

chmorgan commented Oct 14, 2019 via email

@sgreben
Copy link
Owner

sgreben commented Oct 14, 2019

Yes, please! And if you have a better idea for the name than I did (IsInterpolatedAt doesn't exactly roll off the tongue...) please feel free to choose that :) Many thanks!

Sergey

@chmorgan
Copy link
Contributor Author

Hi @sgreben I opened a PR and commented about the implementation. I wasn't sure there was a clean way to figure out if the value was out of range so went the route of extending the existing At() function. I would appreciate feedback and can adjust if necessary.

@sgreben
Copy link
Owner

sgreben commented Dec 7, 2019

Addressed in #3 Thanks!

@sgreben sgreben closed this as completed Dec 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants