# BigFloats parametrised by precision

**URL:** <https://discourse.julialang.org/t/bigfloats-parametrised-by-precision/1663>\
**Category:** General Usage\
**Created:** [January 24, 2017, 3:21pm UTC](https://discourse.julialang.org/t/bigfloats-parametrised-by-precision/1663 "2017-01-24T15:21:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 24, 2017, 3:21pm UTC](https://discourse.julialang.org/t/bigfloats-parametrised-by-precision/1663/1 "2017-01-24T15:21:07Z")

</div>

I vaguely remember that there have been several discussions about parametrising BigFloats according to their precision, and I think I recall that someone already has a package that does this.

Could someone please point me to it?

---

<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 24, 2017, 4:02pm UTC](https://discourse.julialang.org/t/bigfloats-parametrised-by-precision/1663/2 "2017-01-24T16:02:11Z")

</div>

I’d been working on doing that just before JuliaCon 2016, but haven’t had the time to finish it.  
I was trying to accomplish a few things.  
Allow Julia to access in a clean fashion references to BigFloats (very useful for performance if you want to  
do something like sum a bunch of things and not have a huge amount of allocations.  
Make BigFloats much smaller and truly immutable (perform calculations by filling in cached big float reference types, calling MPFR, and then constructing an immutable to return, instead of using a type that points into C allocated memory,  
requiring 16 bytes extra per object for finalizer pointers). This improved performance a lot in my tests.  
Add parameterized BigFloats (using the same scheme as above).  
Add a few specific sizes of parameterized big floats.

---

<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 24, 2017, 4:13pm UTC](https://discourse.julialang.org/t/bigfloats-parametrised-by-precision/1663/3 "2017-01-24T16:13:05Z")

</div>

I think my last version was this: [https://gist.github.com/ScottPJones/37aef2198eb2bc37c5241887cb7117a2](https://gist.github.com/ScottPJones/37aef2198eb2bc37c5241887cb7117a2) (you had even starred my version from just before JuliaCon 😉 )

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 24, 2017, 10:02pm UTC](https://discourse.julialang.org/t/bigfloats-parametrised-by-precision/1663/4 "2017-01-24T22:02:32Z")

</div>

Seems like there are several useful changes mixed up here. Maybe it would be useful to separate them out into different commits to be able to evaluate each separately?

---

<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 25, 2017, 3:24am UTC](https://discourse.julialang.org/t/bigfloats-parametrised-by-precision/1663/5 "2017-01-25T03:24:09Z")

</div>

As soon as I finish revamping the stuff I’m doing for LaTeX, Emoji, Unicode, and HTML entities wrapped up (I’m just finishing debugging the hardest one of the set, Unicode) I can revisit that code.  
Do you have any particular way you think it would be best to organize this?  
The “FloatRef” is kind of the lowest level, that is really the basis for the rest, and might be separable into another package, and then building the others on top of that framework.

---

<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 25, 2017, 3:27am UTC](https://discourse.julialang.org/t/bigfloats-parametrised-by-precision/1663/6 "2017-01-25T03:27:01Z")

</div>

By the way, I think I’ve found a different solution for having a `Float128` type (I didn’t want to call a 128-bit MPFR based type “Float128”, because the other Float types are all based on IEEE, but `BigFloat`s are not), which is wrapping another C library that implements 16, 32, 64, 80, and 128 bit IEEE binary floats.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 25, 2017, 4:12am UTC](https://discourse.julialang.org/t/bigfloats-parametrised-by-precision/1663/7 "2017-01-25T04:12:20Z")

</div>

Personally, it seems to me that it would be best to start with just parametrising the code that currently exists in `base/mpfr.jl`, with no other changes. Then each subsequent substantial change can be a separate commit on top of that.
