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
Duration parsing loses precision by using Double when Long would work #10320
Comments
@melrief pointed to two problematic code locations. Took me a while to agree, but he's right.
In general, that doesn't work on numbers that are odd and use all available digits of In binary arithmetic, that behavior seems plausible, because at the least-significant digits you have
|
@Blaisorblade I don't follow why you conclude that "overall the code works on
|
That statement is technically true on maxPreciseDouble ( I'm questioning both (1) the rounding and (2) parsing into Double, but it seems this issue is only due to (1). That can be confirmed or falsified by testing scala/scala#5913.
As explained by rounding. Doubles up to scala> (1L << 53).toDouble.toLong == (1L << 53)
res3: Boolean = true
scala> (-1L << 53).toDouble.toLong == (-1L << 53)
res7: Boolean = true |
Use round instead of manually trying to convert to a Long. Fixes scala/bug#9949 and scala/bug#10320
I think this is fixed by scala/scala#5796 ? Or is this also still about using |
I remember that seemed dodgy, but I'm not 100% sure how hard it is to change it and if it's better. If you think it's acceptable, feel free to close—not sure I can look into it (and I'm certain I can't look at it soon). |
closing based on the last two comments, but someone might like to double check it |
@melrief pointed out on Gitter that pretty-printing and parsing a Duration does not round-trip in some cases, even for Durations that can be perfectly represented as Long. The code reads the number as a Double and then rounds it to a Long. Not clever:
https://gitter.im/scala/scala?at=5919588a2b926f8a675791b0
I'm looking at his reports, details upcoming.
The text was updated successfully, but these errors were encountered: