Re: [julia-users] Copy a BigFloat?

2014-09-14 Thread Rick Graham
I suppose it's not too bad.

my_nextfloat(x)=with_bigfloat_precision(()-nextfloat(x),x.prec)


Re: [julia-users] Copy a BigFloat?

2014-09-13 Thread Leah Hanson
Do you mean independent for the purposes of editing, or just specifically
for the equality operators?

copy and deepcopy both work for editing purposes:
~~~
julia a=with_bigfloat_precision(()-BigFloat(0.1),64)
1.0001e-01 with 64 bits of precision

julia z=copy(a)
1.0001e-01 with 64 bits of precision

julia z += 2
2.100013552527156068805425093160010874271392822265625e+00
with 256 bits of precision

julia a
1.0001e-01 with 64 bits of precision

julia z
2.100013552527156068805425093160010874271392822265625e+00
with 256 bits of precision

julia z=deepcopy(a)
1.0001e-01 with 64 bits of precision

julia z += 2
2.100013552527156068805425093160010874271392822265625e+00
with 256 bits of precision

julia a
1.0001e-01 with 64 bits of precision
~~~

I believe that BigFloats, like other numeric values types, are immutable.
This means that you can't tell the difference between instances of the same
value using `==` or even `===`. Every time there is a change a or z, it
acts as if it is just changing the binding to point to a new BigFloat [vs.
modifying the current value]. (I am not sure of the specific implementation
details of BigFloat at this time.)

On Sat, Sep 13, 2014 at 6:56 PM, Rick Graham rickhg1...@gmail.com wrote:

 Might be a silly question, but how do you copy a BigFloat so that it is
 independent of the original?


 julia a=with_bigfloat_precision(()-BigFloat(0.1),64)
 1.0001e-01 with 64 bits of precision


 julia z=copy(a)
 1.0001e-01 with 64 bits of precision


 julia a.d==z.d
 true


 julia z=deepcopy(a)
 1.0001e-01 with 64 bits of precision


 julia a.d==z.d
 true






Re: [julia-users] Copy a BigFloat?

2014-09-13 Thread Rafael Fourquet
BigFloats are indeed immutable in spirit but not really:

julia BigFloat.mutable == isimmutable(big(0.1))
true

So copy is a no-op (returns its argument as for every number), and deepopy
returns a new instance (deepcopy(a) === a is false), but then there is no
public API to mutate a or its copy.  So there is no use for deepcopy on
BigFloats in client code, they behave as Float64.


Re: [julia-users] Copy a BigFloat?

2014-09-13 Thread Rick Graham
I wanted an easy way to do nextfloat(a), taking into account that 'a' doesn't 
have the global BigFloat precision.  I.e., what's the nextfloat of the 64-bit 
precision (in this case) BigFloat and return a 64-bit precision BigFloat.

I could write a function that does this, but I thought that there might be 
something easier than having to extract the precision of each BigFloat and 
nextfloat'ing with that global BigFloat precision.