big float variable (visibility)


#1

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 ?


#2

rand(BigFloat)?


#3

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?


#4

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


#5

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.


#6

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


#7

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.


#8

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


#9

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


#10

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:


#11

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:


#12

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?


#13

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


#14

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?


#15

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