Does copy() always create a valid copy of BigFloat?

Does copy() always create a valid copy of BigFloat?

x = big(1.0)   # -> 1.0
y = copy(x)    # -> 1.0
x == y         # -> true
x += 1         # -> 2.0
x == y         # -> false
y              # -> 1.0

Looks correct in my eyes…

1 Like

What else would you expect to happen?

1 Like

for bigint copy is a noop


I don’t see anything contradicting that here either - adding one to the original of a copied BigInt surely also decouples the two variables? Both are considered immutable for julia after all.

1 Like

I found a little faster way for bool^float than Speed up `x::Bool ^ y::Float64` and decided to tinker a bit with float^bool /

pow_fast_1(x::T, y::Bool) where T <: AbstractFloat = y ? x : T(1)
pow_fast_2(x::BigFloat, y::Bool) = y ? copy(x) : big(1.0)

I found that pow_fast_2 is faster than pow_fast_1 and native ^ for BigFloat, but copy() in pow_fast_2 is not really needed

what do you mean “make PR” ?

something unexpected)

by make a PR I mean make a pull request to the julia repository to speed up Float64^Float64 since any way to do Bool^Float64 faster than what I posted would also allow for an improvement to Float64^Float64