-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
itrunc -> trunc, etc, fix Int128 vs float comparisons #9133
Conversation
Strange that this seems to work for me locally on linux64 and win64, but fails on Travis at the random tests - something to do with the ziggurat tables. And on linux32 and win32 it segfaults during bootstrap at
|
I'm looking into the random tests now: it seems to be a recent change, as I didn't get the errors until I rebased. I suspect the 32-bit problems might have something to do with using the built-in intrinsics for conversions. Unfortunately I don't have access to a 32-bit test machine. Is there a way I can force a 32-bit build on a 64-bit machine? |
On Linux, kinda-sorta-mostly. Put the following in
Best to do this in a fresh clone since it'll need to rebuild 32-bit versions of all the deps. |
Oh and that explains the difference between running it locally vs on travis, since travis runs on a test merge commit of a PR into master. cc @rfourquet who has made a bunch of recent changes related to the RNG and might be able to help here. |
I think I've figured out the problem with the random tests: it's calling |
@andreasnoack is this a problem with the Ziggurat tables? |
The test checks that the generated tables are |
@andreasnoack Done. |
This is great – I've been wanting to do this for quite a while. I'm still surprised by how much nicer it feels. |
The fact that the ziggurat tables were wrong is really unsettling though. |
Maybe the failure of |
@nalimilan it's not failing tests on 32 bit, it's segfaulting during system image bootstrap.
This is the bug you meant right? That is worrying. It would have maybe made sense to split the bugfix apart from the API change here, but too late now I suppose. |
@tkelman that's probably not a bad idea, because I guess this would be desirable for backporting. I'll see what I can do. |
I'm not having any luck getting the 32-bit build to work. I'll try rewriting the offending functions and see how I go. |
On Linux or OSX? If you're on Linux it should mostly work and I can have a go at fixing whatever's wrong, no idea about OSX though. |
@tkelman I keep getting openlibm errors: lots of lines like
|
Was that in an existing build? You'll have to |
I tried that as well, then LLVM fails:
|
@StefanKarpinski The tables were not wrong. The variates passed BigCrush which is the only thing we can really use to verify them. There is room enough among the double precision numbers to move the table borders a single float here and there. @simonbyrne Just ran BigCrush on PR and the tests passed. |
@andreasnoack could you try it on release-0.3 with the patch from #9138 applied? |
@tkelman The tests just finished and they all passed. |
Wonderful. Were these the same ones that were failing before (#6464)? Or is uniform still messed up and these are just errors in the last place that subtly distorted the distribution? |
The tricky thing is that |
Okay, well sounds like we should merge #9138 anyway. @simonbyrne I've never seen that one before but it looks like you might need to install |
From what I can tell, |
@tkelman I've now implemented all the 128-bit conversions in native Julia, so would you be able to try the 32-bit machines again? |
sure. on 32 bit linux I get edit: same on win32. if you can't get building with |
I've found vagrant makes VM's super easy to use, FWIW. Your last commit here 2322a7c passes tests for me on linux32 and win64, and although it brings #8895 back on win32 I suspect that's a sign of some deeper underlying problem with I'll leave it to others to make the call on this, but looks okay to me right now. |
@@ -477,7 +477,7 @@ function ^{T<:Complex}(z::T, p::T) | |||
|
|||
# apply some corrections to force known zeros | |||
if pim == 0 | |||
ip = itrunc(pr) | |||
ip = trunc(pr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be trunc(Int,pr)
? isodd
is used on the result below. (Or trunc(Integer,pr)
I guess.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this was intentional. ip
is only used in a comparison with pr
, so it doesn't really make sense to convert to an integer, and then back again.
On second thoughts, this should really just be an isinteger
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good. Then we just need to take care of the isodd
, which isn't defined for floating point and should probably stay that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, missed that one. Should be fixed now.
💯 This is an awesome change. |
2067415
to
6c63a10
Compare
Ok, I think this is ready to go. Maybe also a NEWS item? |
done. |
itrunc -> trunc, etc, fix Int128 vs float comparisons
I don't know whether this is fair to ask, but certainly I wouldn't mind if this type of change went along with an enhancement to Compat.jl. In this case, I did it myself, see JuliaLang/Compat.jl#20. |
I do think we need to start pairing breaking changes and deprecations with Compat support for same. |
See JuliaLang/julia#9133 This uses Compat to ensure backwards-compatibility
Does anyone besides me find the recommendation to use |
It's necessary for correctness of the deprecation definition, e.g. to replace |
Thanks for explaining. |
As far as I can tell, the only limitation is the flexibility of the current |
Compatibility for trunc(T, x) etc (Julia PR #9133)
This merges
itrunc
intotrunc
,iceil
intoceil
,ifloor
intofloor
andiround
intoround
, implementing most of #8728 (and fixes #3040). Some other changes were made along the way:trunc(Int,x)
is bounds checked. The old "fast-but-unsafe"itrunc
behaviour is now available viaBase.unsafe_trunc
(I'm open to better suggestions for names)__floattidf
and__fixdfti
. If these aren't available on all platforms, it should be fairly easy to implement them in Julia (e.g. here).pi < pi
gives error #8411).itrunc(::BigFloat)
, which was doing rounding, not truncation (e.g.itrunc(big(2.7)) = 3
).round(Int,x)
is implemented using the+prevfloat(0.5)
trick mentioned in Add LLVM intrinsics for floor/ceil/trunc/abs. #8364 (comment). This does depend on rounding modes, but I could change it to using the+(x-trunc(x))
method once we have a fasttrunc
(Add LLVM intrinsics for floor/ceil/trunc/abs. #8364).Sorry for the mammoth PR. I didn't intend to do all this at once, but it was difficult to split apart.