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 ?


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)

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

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

julia> setprecision(30) do

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

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

and are you talking about show.jl as in

julia> x = big"0.1"

julia> s = string(x)

julia> s[1:10]

julia> s[end-10:end]

The printing for BigFloat is here:

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

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

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