lang: funcs: Add epsilon checks to operator_polyfunc#578
Conversation
|
@dbakong I think you're on the right track, the epsilon stuff should be done at the top and only once. As either a var or a const or an init() or a combination. See what works =D |
4a46cde to
65e8b75
Compare
|
@purpleidea thanks, I moved it to the top. |
0c043c6 to
a8cca31
Compare
| ) | ||
|
|
||
| func init() { | ||
| epsilon := func() float64 { |
There was a problem hiding this comment.
I bet you can do even better! this computation still repeats each time.
0d05448 to
1ef8e91
Compare
| operatorArgName = "op" // something short and arbitrary | ||
| ) | ||
|
|
||
| var epsilon = func() float64 { |
There was a problem hiding this comment.
-
How can you simplify this?
-
It still runs for each use of the operator.
Can we do better?
1ef8e91 to
0398644
Compare
purpleidea
left a comment
There was a problem hiding this comment.
Since you have this pattern:
math.Abs(input[0].Float()-input[1].Float()) > epsilon
Repeated very often, maybe it makes sense to have it be a helper function? Write this as a lambda, right under the epsilon definition. Secondly, check the > above. Is it that or do we want >= ?
Being precise about > vs >= is exactly the point of this problem. Review all the instances in your patch and clean up the other issues mentioned and resubmit!
I hope this is fun!
Thanks!
| V: func(input []types.Value) (types.Value, error) { | ||
| // TODO: should we do an epsilon check? | ||
| // epsilon check | ||
| if math.Abs(input[0].Float()-input[1].Float()) <= epsilon { |
There was a problem hiding this comment.
Should this be < instead of <= ?
| V: func(input []types.Value) (types.Value, error) { | ||
| // TODO: should we do an epsilon check? | ||
| // epsilon check | ||
| if math.Abs(input[0].Float()-input[1].Float()) <= epsilon { |
There was a problem hiding this comment.
I think the more elegant way to write this is to start off with something like:
result := false
And then in you condition you do: result = true
And at the end you put in the bool into the &BoolValue as result. (Similarly for other cases.)
| V: func(input []types.Value) (types.Value, error) { | ||
| // TODO: should we do an epsilon check? | ||
| // epsilon check | ||
| if math.Abs(input[0].Float()-input[1].Float()) > epsilon { |
| ) | ||
|
|
||
| func init() { | ||
| // epsilon definition |
There was a problem hiding this comment.
This is an unhelpful comment. Explain why this is the case, since the code is not intuitive.
0398644 to
bb8d5da
Compare
|
@dbakong The epsilon helper doesn't make sense... Where is Put the patch back to the way it was before and get all the < > <= >= stuff perfect. LMK here when ready. |
297f4b4 to
8e3372a
Compare
|
@purpleidea I think I got the last missing operator update. Please review. |
8e3372a to
02f7232
Compare
8f68996 to
372b5ef
Compare
372b5ef to
d2586d2
Compare
d2586d2 to
6da48d2
Compare
2319f4f to
04f5ba6
Compare
0995279 to
a665861
Compare
fe2313c to
271a94e
Compare
b8072b2 to
380004b
Compare
37fdda9 to
5f4ae05
Compare
3221a93 to
4ad2b9a
Compare
b7ee313 to
cb70565
Compare
Tips:
please read the style guide before submitting your patch:
docs/style-guide.md
commit message titles must be in the form:
topic: Capitalized message with no trailing periodor:
topic, topic2: Capitalized message with no trailing periodor format a single golang file correctly:
Thanks for contributing to mgmt and welcome to the team!