# big float variable (visibility)

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 ?

rand(BigFloat)?

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?

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

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

1 Like

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> 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.

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

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.

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
while loading C:\Users\Diger\Documents\Julia\functions\bf_rand.jl, in expression starting on line 1

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


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

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
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

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?

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

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?

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) 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.