-
Notifications
You must be signed in to change notification settings - Fork 538
-
Notifications
You must be signed in to change notification settings - Fork 538
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
Ugh signed zeros #187
Comments
I don't have any helpful input on your suggestion, but I just want to 👏 for an excellent writeup with an introductory paragraph that guaranteed I would read on. |
So, first of all, welcome to the hell that is IEEE-754 on the JVM. We're talking about floating-point, so obviously things are going to be terrible no matter what we do. I'm going to lay out my own feelings on the "right thing" to do, with the proviso that there are obviously problems. First of all, I have accepted that type classes parameterized on Given this background, I think Algebra's behavior is wrong and Scalaz's is correct. The reason I mentioned floating-point type class instances not being law-abiding is that Scalaz's instance (like Spire's) breaks the law that The other "advantage" of this view is that it keeps things like So what should Circe do? I propose one of these:
Obviously my plan embraces inconsistency, but due to the interaction of IEEE and Java there is fundamental inconsistency between |
Thanks for the detailed answer, @non! I still think I want to go with your second option. If someone said they want to distinguish between |
This is fixed in #189, which distinguishes positive and negative zero values as JSON numbers. |
Update sbt-mima-plugin to 0.6.1
Let me start by saying that I spent my entire life up until about an hour ago without realizing what a shitshow signed zeros are, and I wish I could go back to a state of innocence, so you might want to close the tab and move on.
First for the basics:
Hurray, that makes no sense (but at least you might have seen it before).
Cats and Scalaz also disagree:
Apparently IEEE 754 says something like "positive and negative zeros are distinct but equal", and that's why Java's primitive floating point types make them equal. Cats (and Algebra, although each defines its own instance) seems to be taking a more principled stand than Scalaz here on "distinct but equal" not making any sense (I don't know what the actual motivations for the choices here are, but I'm curious).
Argonaut says all zero JSON numbers are equal:
But it's perfectly happy to round-trip negative zeros if they have a fractional part:
This seems really wrong to me—if two things serialize differently, the
scalaz.Equal
instance shouldn't say they're the same.circe currently round-trips both cases (at least with Jawn as the parser—other parsers may behave in such a way that this isn't possible), but also says they're all equal:
I think I'd like to keep the current round-tripping behavior (I want circe to be able to distinguish distinct JSON values in as many cases as is reasonably possible), but to make positive and negative values not equal whether or not there's a fractional part.
Any objections?
The text was updated successfully, but these errors were encountered: