JuliaLang/julia — pull request #9133 by simonbyrne (2014-11-24 10:47:41+00:00)
Title: itrunc -> trunc, etc, fix Int128 vs float comparisons

This merges `itrunc` into `trunc`, `iceil` into `ceil`, `ifloor` into `floor` and `iround` into `round`, 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 via `Base.unsafe_trunc` (I'm open to better suggestions for names)

* Floating point <-> 128-bit integer conversions now use standard llvm intrinsics when possible. These seem to be faster and more accurate (there was some double-rounding issues in the old code). From what I can tell, these call out to libc functions such as `__floattidf` and `__fixdfti`. If these aren't available on all platforms, it should be fairly easy to implement them in Julia (e.g. [here](https://github.com/freebsd/freebsd/blob/c9ca7e675137304db25e1277aa1b7d3481aa5c15/contrib/compiler-rt/lib/floattidf.c)).

* Fixed floating point vs 128-bit integer comparisons. All float vs integer comparisons should now be correct (cf #8411).

* Fixed `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 https://github.com/JuliaLang/julia/pull/8364#issuecomment-56283375.

Sorry for the mammoth PR. I didn't intend to do all this at once, but it was difficult to split apart.