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
SI-3235 math.round() returns wrong results for Int and Long #3581
Conversation
@non @soc @adriaanm - This is as minimal of a fix as I can generate. It fixes the issue, nothing more or less. No |
👍 |
No. No. No. No. No. I'm slowly losing my mind. What's wrong with not making things any worse? |
@soc - I'm baffled. Why is this making things worse? |
As mentioned for the umpteenth times, the return types are all over the place. Yes, it's kind of unfortunate that it is that way for If you think this is the right approach, please, in god's name finally tell me what
Yes. It's better to be broken in one way, than to be broken in different ways, depending on the Scala version. If you can't or don't want to fix it, just leave it as-is. |
@soc - You're conflating two different issues. One: is there a more regular way to do this? Yes, there is. Unfortunately it breaks existing code and existing expectations. Two: can we protect users from pure nonsense? Yes. This is how. (Adding a deprecation warning would be even better. For reasons I don't understand, you seemed to object to that. It's less essential than the method that catches the problematic behavior, though, so I left it off this time.) When we have time to redo the entire numeric hierarchy and/or redo whether primitives get promoted, we can revisit the issue. In the meantime, I don't think leaving unguarded pitfalls is doing anyone any favors. I don't think this is a time when regularity should trump correctness. As to |
@soc it would help to understand why it's bad for the return types to be On Tuesday, February 25, 2014, soc notifications@github.com wrote:
|
@Ichoran The approach I have proposed doesn't break "existing code and existing expectations" PLUS it's more regular PLUS it's protecting users from nonsense.
And guess who did a lot of work to prevent that from being a type error in the first place? Hint: It wasn't me. That we basically have to sprinkle
Despite the fact that somehow most languages/libraries know exactly what is meant by "rounding a complex", just pick a different random numeric type (which in your opinion needs a rounding operatiuon) and explain how you are going to fit the value of that type's @adriaanm How is The example with the typeclass was an example in which I tried to make it more obvious why it is important to be consistent. Consistency matters even if we didn't have that typeclass. And as mentioned above, adding an additional type member comes with additional complexity, still doesn't answer what the type member should be and what's the actual benefit of it.
What's the supposed type member of such typeclass instances and where would they differ in a meaningful way from returning the same type itself? |
Very roughly:
Let's be realistic. We really can't be working on design the day the RC is cut. The debate was over which methods we were going to deprecate and which ones needed to be overridden to avoid the unexpected widenings during rounding. |
@soc - Adding My fix is basically your fix, less the clutter of Also: you already can't round |
Finally, it seems desirable to get a long when rounding a double, and not a double (so you can't have the T => T signature for the round function, it must be ad-hoc). I'm not exactly sure, but I'd expect longs to be faster for many operations (say you're subtracting the rounding of two doubles). |
@adriaanm - Due to implementation details, |
Eh what ... and now we are back exactly at square one, converting values to types which can't represent those values? The reason is called "consistency". Something we valued quite a lot in the past. Maybe our standards have changed and I didn't get the notice?
Why? For all the excitement those invisible bugs bring to developers?
I'm wondering what's more ironic: That you first fought tooth and nails against the principled solution of not converting unrelated, incompatible numeric types and are now complaining that the alternatives suck ... or that you don't even seem to realize that. We would have never needed to add these methods if we just stopped converting numbers just for fun. But considering that we are stuck with it, you are complaining that having to play defense against those conversions is kind of inconvenient ... no shit Sherlock!? I would have preferred a better solution, so don't blame the unfortunate consequences of your choices on me. |
Please edit your comment for tone. We are having a technical discussion Please also consider the big picture. This is one small corner of the On Tuesday, February 25, 2014, soc notifications@github.com wrote:
|
Minimal fix for SI-3235. This minimal fix includes deprecation messages to aid detection of probable errors. Test verifies behavior: the correct values are returned, and deprecation messages are emitted.
New interpretation of minimal--minimal and maximally helpful for correctness. @soc - Deprecation (or another way to generate a warning or error) can catch this single extra-problematic case for widening. This is the best minimal solution (for correctness), so I'm changing my PR to that. It will fix bugs and provide an alert about changed behavior. I apologize if it offends the sensibilities of some to use this (not very elegant) mechanism to catch widening in this case where it's really problematic. @non - One more check, please? @adriaanm - I doubt it's possible to do any better for code correctness with a simple fix (at least with the annotations I know of). |
@soc - Incidentally, for |
That's exactly what I'm doing. Not making things worse than they currently are, so that we can have a realistic change for a better fix in the future instead of piling hacks upon hacks. Anyway, things work as they are supposed to in my branch without requiring any of these hacks here, and that's all what I'm going to care about in the future. |
Ok, thanks for your input and your patience. I'll consider this PR good to go then, assuming @non agrees. |
👍 |
Great! One small step for scalac,.... |
SI-3235 math.round() returns wrong results for Int and Long
|
@som-snytt - But you missed the most interesting (devious?) part:
|
Minimal fix for SI-3235.
No deprecation or migration messages; if anyone used this to clip Long into Int (with rounding errors from Float), they will observe altered behavior.
Test verifies behavior.