# big float variable (visibility)

**URL:** <https://discourse.julialang.org/t/big-float-variable-visibility/7423>\
**Category:** General Usage\
**Created:** [November 30, 2017, 10:11pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423 "2017-11-30T22:11:11Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diger/32/36786_2.png) [@Diger](https://discourse.julialang.org/u/Diger)\
**Post date:** [November 30, 2017, 10:11pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/1 "2017-11-30T22:11:11Z")

</div>

first of all how do I generate a random bigfloat variable?  
rand() is not bigfloat.

second: If I have a bigfloat with 10^7 digits, can I suppress most digits and only show say the first 10 or 20 ?

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [November 30, 2017, 10:52pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/2 "2017-11-30T22:52:46Z")

</div>

rand(BigFloat)?

---

<div class="post-metadata">

**Author:** ![Diger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diger/32/36786_2.png) [@Diger](https://discourse.julialang.org/u/Diger)\
**Post date:** [November 30, 2017, 11:00pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/3 "2017-11-30T23:00:51Z")

</div>

Actually rand(BigFloat) does not work for me…I am using v0.5 I think  
What keywords can I set here btw?  
Like numbers for the array, types likeInt64, BigFloat, …  
Anything else?

Do you also know an answer to the 2. question?

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [December 1, 2017, 6:08am UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/4 "2017-12-01T06:08:00Z")

</div>

Ah, sorry, I was on master not v0.6 or v0.5.

```julia
julia> rand(BigFloat)
9.144825141697307113566304316490034379378385773529233716587710664758380851274433e-02

```

Luckily, v0.7/v1.0 should be out soon. The functionality was added in July

[https://github.com/JuliaLang/julia/commit/c3c950708166a0909bc237db1e3bb3b6ec0eb780](https://github.com/JuliaLang/julia/commit/c3c950708166a0909bc237db1e3bb3b6ec0eb780)

---

<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:** [December 1, 2017, 6:42am UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/5 "2017-12-01T06:42:45Z")

</div>

You can convert it to `Float64` if it is within range. If not, there is missing functionality which should enable you to do something like

```julia

julia> a = setprecision(1000) do
           big"0.1"
           end
1.000000000000000000000000000000000000000000000000000000000000000000000000000002e-01

julia> setprecision(30) do
           a
           end
1.000000000000000000000000000000000000000000000000000000000000000000000000000002e-01

```

You would probably expect the latter to make a BigFloat with precision 30. I think I had an open issue or PR about this.

---

<div class="post-metadata">

**Author:** ![Diger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diger/32/36786_2.png) [@Diger](https://discourse.julialang.org/u/Diger)\
**Post date:** [December 2, 2017, 2:57pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/6 "2017-12-02T14:57:11Z")

</div>

Thanks…Is is likewise possible to show only the last digits?  
Or sth like the first 10 and the last 10 digits?

---

<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:** [December 2, 2017, 4:37pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/7 "2017-12-02T16:37:18Z")

</div>

You could do string(x) and then manipulate the string as you like.

Or you could override show for a BigFloat and follow the source code for it to do what you’re asking.

---

<div class="post-metadata">

**Author:** ![Diger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diger/32/36786_2.png) [@Diger](https://discourse.julialang.org/u/Diger)\
**Post date:** [December 2, 2017, 6:34pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/8 "2017-12-02T18:34:14Z")

</div>

hello rfourquet:  
Actually did you post it so that I can just copy paste and include it?  
Because it says:  
ERROR: LoadError: UndefVarError: CloseOpen\_64 not defined  
in include\_from\_node1(::String) at .\loading.jl:488  
while loading C:\Users\Diger\Documents\Julia\functions\bf\_rand.jl, in expression starting on line 1

---

<div class="post-metadata">

**Author:** ![Diger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diger/32/36786_2.png) [@Diger](https://discourse.julialang.org/u/Diger)\
**Post date:** [December 2, 2017, 6:39pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/9 "2017-12-02T18:39:03Z")

</div>

dpsanders: can you give me an example for the string(x) manipulation maybe?

and are you talking about show.jl as in  
v0.5\Polynomials\src  
v0.5\ColorTypes\src  
v0.5\BinDeps\src

---

<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:** [December 2, 2017, 7:05pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/10 "2017-12-02T19:05:56Z")

</div>

```julia

julia> x = big"0.1"
1.000000000000000000000000000000000000000000000000000000000000000000000000000002e-01

julia> s = string(x)
"1.000000000000000000000000000000000000000000000000000000000000000000000000000002e-01"

julia> s[1:10]
"1.00000000"

julia> s[end-10:end]
"0000002e-01"

```

The printing for BigFloat is here:

[https://github.com/JuliaLang/julia/blob/255b5d5c8ce0970258e4ce28c4239d62feabd842/base/mpfr.jl#L911](https://github.com/JuliaLang/julia/blob/255b5d5c8ce0970258e4ce28c4239d62feabd842/base/mpfr.jl#L911)

---

<div class="post-metadata">

**Author:** ![Diger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diger/32/36786_2.png) [@Diger](https://discourse.julialang.org/u/Diger)\
**Post date:** [December 2, 2017, 10:55pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/11 "2017-12-02T22:55:16Z")

</div>

When I want to see what  
function \_calculate\_buffer\_size!(buf, fmt, x::BigFloat)  
does, do I need to redefine it in my file im running, because when I do so it says \_calculate\_buffer\_size!(…) overwritten in module main?

However if I do not it just tells me:  
ERROR: LoadError: UndefVarError: \_calculate\_buffer\_size! not defined  
in include\_from\_node1(::String) at .\loading.jl:488  
while loading C:\Users\Diger\Documents\Julia\various math problems\bigfloat\_cosx.jl, in expression starting on line 15

In any case I cannot call it ☹

---

<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:** [December 2, 2017, 11:08pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/12 "2017-12-02T23:08:19Z")

</div>

Those are internal functions.  
You can either redefine them all yourself (possibly changing the names), or call them as  
`Base.MPFR._calculate_buffer_size!`.

But I really meant that you could write your own code based on those.

In any case, what exactly are you trying to do?

---

<div class="post-metadata">

**Author:** ![Diger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diger/32/36786_2.png) [@Diger](https://discourse.julialang.org/u/Diger)\
**Post date:** [December 2, 2017, 11:16pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/13 "2017-12-02T23:16:19Z")

</div>

Yes I know…I’m just very inexperienced, so I just try to figure out what everything does.  
Given the example above say I would like to change it such that it prints  
123134…1234141515  
of some BigFloat.

PS: What is the argument it wants for “buf” and “fmt”  
coz when I redefine it myself it says:  
ERROR: UndefVarError: buf not defined  
in anonymous at .\<missing\>:?

However I actually thought buf and fmt were filled by the ! function

---

<div class="post-metadata">

**Author:** ![Diger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diger/32/36786_2.png) [@Diger](https://discourse.julialang.org/u/Diger)\
**Post date:** [December 3, 2017, 4:42pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/14 "2017-12-03T16:42:55Z")

</div>

You still there?

Btw: What does MPFR in Base.MPFR.\_calculate\_buffer\_size! stand for?  
It still tells me:  
julia\> Base.MPFR.\_calculate\_buffer\_size!(buf,fmt,x)  
ERROR: UndefVarError: \_calculate\_buffer\_size! not defined

I just tried to use the ccall() function in the example  
julia\> t = ccall( (:clock, “libc”), Int32, ())  
from the manual  
but it tells me that I am missing the c-library “libc”.  
So now I’m wondering whether I do have all the libraries for e.g. \_caluclate\_buffer\_size! above  
since apparently it needs the library libmpfr, right?

---

<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:** [December 3, 2017, 7:22pm UTC](https://discourse.julialang.org/t/big-float-variable-visibility/7423/15 "2017-12-03T19:22:36Z")

</div>

You can just use what I put previously to write a function `print_it(x::BigFloat)`.  
Probably it’s not worth messing with anything internal.

MPFR is the [underlying library([GNU MPFR - Wikipedia](https://en.wikipedia.org/wiki/GNU_MPFR)) that Julia wraps for BigFloat functionality.

Somebody else will have to chime in about why those libraries are not available – presumably it’s a Windows issue.
