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

**URL:** <https://discourse.julialang.org/t/does-copy-always-create-a-valid-copy-of-bigfloat/90672>\
**Category:** General Usage\
**Created:** [November 22, 2022, 10:26pm UTC](https://discourse.julialang.org/t/does-copy-always-create-a-valid-copy-of-bigfloat/90672 "2022-11-22T22:26:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [November 22, 2022, 10:26pm UTC](https://discourse.julialang.org/t/does-copy-always-create-a-valid-copy-of-bigfloat/90672/1 "2022-11-22T22:26:11Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [November 22, 2022, 10:59pm UTC](https://discourse.julialang.org/t/does-copy-always-create-a-valid-copy-of-bigfloat/90672/2 "2022-11-22T22:59:44Z")

</div>

Looks correct in my eyes…

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [November 22, 2022, 11:05pm UTC](https://discourse.julialang.org/t/does-copy-always-create-a-valid-copy-of-bigfloat/90672/3 "2022-11-22T23:05:40Z")

</div>

What else would you expect to happen?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [November 22, 2022, 11:06pm UTC](https://discourse.julialang.org/t/does-copy-always-create-a-valid-copy-of-bigfloat/90672/4 "2022-11-22T23:06:08Z")

</div>

for bigint copy is a noop

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [November 22, 2022, 11:08pm UTC](https://discourse.julialang.org/t/does-copy-always-create-a-valid-copy-of-bigfloat/90672/5 "2022-11-22T23:08:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [November 22, 2022, 11:30pm UTC](https://discourse.julialang.org/t/does-copy-always-create-a-valid-copy-of-bigfloat/90672/6 "2022-11-22T23:30:03Z")

</div>

I found a little faster way for bool^float than [Speed up `x::Bool ^ y::Float64`](https://discourse.julialang.org/t/speed-up-x-bool-y-float64/90601) and decided to tinker a bit with float^bool /

```julia
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” ?

---

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [November 22, 2022, 11:35pm UTC](https://discourse.julialang.org/t/does-copy-always-create-a-valid-copy-of-bigfloat/90672/7 "2022-11-22T23:35:48Z")

</div>

something unexpected)

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [November 22, 2022, 11:37pm UTC](https://discourse.julialang.org/t/does-copy-always-create-a-valid-copy-of-bigfloat/90672/8 "2022-11-22T23:37:27Z")

</div>

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`
