# Moving BigFloat to stdlib?

**URL:** <https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545>\
**Category:** Internals & Design\
**Created:** [January 23, 2018, 3:43pm UTC](https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545 "2018-01-23T15:43:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 23, 2018, 3:43pm UTC](https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545/1 "2018-01-23T15:43:53Z")

</div>

With all the other things moving out of Base, there are not really many places where BigFloat is used anymore:

In `int.jl`, there is a parsing routine that would simply move to `stdlib/BigFloat.jl`  
`mpfr.jl` would move to `stdlib/BigFloat.jl`  
In `printf.jl` (which I’d thought had already moved to `stdlib/Printf.jl`), there is some code to print out BigFloats and BigInts.  
There’s a single function in `hashing2.jl`, which also would just move to `stdlib/BigFloat.jl`.  
There are a few lines in `sysimg.jl`:

```julia
include("mpfr.jl")
using .MPFR
big(n::Integer) = convert(BigInt,n)
big(x::AbstractFloat) = convert(BigFloat,x)
big(q::Rational) = big(numerator(q))//big(denominator(q))

```

There’s a line in `exports.jl`.

The only real use is in `irrationals.jl`, and I believe the BigFloat part of irrationals could be moved also out.

This would remove a large dependency from Base (the MPFR library),  
and allow `BigFloats` to be updated without waiting on the Julia timeline.

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [January 23, 2018, 4:05pm UTC](https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545/2 "2018-01-23T16:05:26Z")

</div>

Maybe i don’t have the full picture, but it looked like stdlib is still a dependency (i.e. you don’t run julia without stdlib)?

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 23, 2018, 4:07pm UTC](https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545/3 "2018-01-23T16:07:06Z")

</div>

I’d thought the whole point of moving things to stdlib was so that you _could_ run julia without the parts you didn’t want, such as LinAlg, etc.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 23, 2018, 4:52pm UTC](https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545/4 "2018-01-23T16:52:37Z")

</div>

> [@lobingera](#):
>
> Maybe i don’t have the full picture, but it looked like stdlib is still a dependency (i.e. you don’t run julia without stdlib)?

> [@ScottPJones](#):
>
> I’d thought the whole point of moving things to stdlib was so that you could run julia without the parts you didn’t want, such as LinAlg, etc.

Yeah, it’s still a dependency of Julia proper, but IIUC it’s adding to the Base installation through the system image. So you then download Julia and build a version without them just by deleting a few things from the sysimg.jl

> <https://github.com/JuliaLang/julia/blob/3bccded84d14bbfbbbdb345101738b593b0d894f/base/sysimg.jl#L505-L527>

and since it’s disconnected from Base proper it won’t break anything. I am not sure whether it would still build MPFR, or the legal issues with the licensing at that point.

But anyways I think that BigFloat could go all the way to a package and \>90% of people’s codes wouldn’t change, which would fix the issue entirely but could only be done in a 1.x if it’s in the stdlib instead of Base.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [January 23, 2018, 5:20pm UTC](https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545/5 "2018-01-23T17:20:31Z")

</div>

Unfortunately, we need big ints and big floats in the array hashing code to compute the difference between two subsequent elements in an array without any overflow or precision loss. That’s not great, but so far we haven’t found any other solution (see [this PR](https://github.com/JuliaLang/julia/pull/16401/)). This system could be easily disabled via a build option, and hashing of ranges would then be O(N) instead of O(1), but by default I’m afraid we’ll have to keep the types in Base. Though we can avoid exporting them from Base and use a stdlib module for that instead.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 23, 2018, 5:27pm UTC](https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545/6 "2018-01-23T17:27:47Z")

</div>

Where are they being used in the array hashing code? I’d looked for all methods using `BigFloat`, but must have missed some places then where they are being used.

> [@nalimilan](#):
>
> Though we can avoid exporting them from Base and use a stdlib module for that instead.

That’s my big issue, if they can be moved to stdlib, can’t they then be updated independently of Julia itself?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [January 23, 2018, 9:39pm UTC](https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545/7 "2018-01-23T21:39:17Z")

</div>

> [@ScottPJones](#):
>
> Where are they being used in the array hashing code? I’d looked for all methods using BigFloat, but must have missed some places then where they are being used.

It’s used for `widen`. But the method doesn’t take `BigFloat` arguments, it returns `BigFloat`.

> [@ScottPJones](#):
>
> That’s my big issue, if they can be moved to stdlib, can’t they then be updated independently of Julia itself?

I’m afraid that if the type is defined in Base, it’s going to be quite complex to update the stdlib module independently. I guess some interfaces could be updated, but it would have to remain compatible with what lives in Base.

---

<div class="post-metadata">

**Author:** ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)\
**Post date:** [January 24, 2018, 12:06am UTC](https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545/8 "2018-01-24T00:06:07Z")

</div>

Opened [https://github.com/JuliaLang/julia/issues/25716](https://github.com/JuliaLang/julia/issues/25716)

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [January 24, 2018, 6:56pm UTC](https://discourse.julialang.org/t/moving-bigfloat-to-stdlib/8545/9 "2018-01-24T18:56:18Z")

</div>

9 posts were split to a new topic: [Array hashing is complicated](https://discourse.julialang.org/t/array-hashing-is-complicated/8567)
