# Why is not big(1) === big(1)

**URL:** <https://discourse.julialang.org/t/why-is-not-big-1-big-1/2750>\
**Category:** New to Julia\
**Created:** [March 18, 2017, 4:27pm UTC](https://discourse.julialang.org/t/why-is-not-big-1-big-1/2750 "2017-03-18T16:27:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [March 18, 2017, 4:27pm UTC](https://discourse.julialang.org/t/why-is-not-big-1-big-1/2750/1 "2017-03-18T16:27:13Z")

</div>

For most immutable numeric types `a === b` if `a == b`. For example:

```julia
julia> Int128(1) === Int128(1)
true

```

This is not the case with BigInt and BigFloat

```julia
julia> BigInt(1) === BigInt(1)
false

julia> BigFloat(1) === BigFloat(1)
false

```

Comparison using `==` still works as expected, so `big(1) == big(1)`, but this does not extend to comparing `struct`s that contain `BigInt` or `BigFloat` (unless `==` is explicitly overloaded) because `==` defaults to `===`.

```julia
julia> immutable T
         x::BigInt
       end

julia> T(1) == T(1)
false

```

Is there a reason for this behavior, or it it a bug?

(I’ve tried this under 0.5.1 and 0.6.0-pre.alpha.76.)

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [March 18, 2017, 4:43pm UTC](https://discourse.julialang.org/t/why-is-not-big-1-big-1/2750/2 "2017-03-18T16:43:58Z")

</div>

`===` is for comparing identity, not for comparing values. This is not a bug and is expected given that `BigInt` and `BigFloat` are mutable types.

The fact that `BigFloat` and `BigInt` are implemented as mutable types and therefore can be distinguished even when two objects holds the same value is an implementation detail that you shouldn’t need to care about if you just want to write generic code that handles numbers. If you are doing something specific to these types and somehow cares about their identity then you’ll need too handle this.

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [March 18, 2017, 4:51pm UTC](https://discourse.julialang.org/t/why-is-not-big-1-big-1/2750/3 "2017-03-18T16:51:14Z")

</div>

OK. Thanks! I didn’t realize `BigInt` and `BigFloat` were mutable.

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [March 19, 2017, 6:14am UTC](https://discourse.julialang.org/t/why-is-not-big-1-big-1/2750/4 "2017-03-19T06:14:53Z")

</div>

If they are considered numbers, they should be immutable and `===` should work: this has already been discussed ([here](https://discourse.julialang.org/t/idea-for-setting-both-mutables-and-immutables-without-allocation/1318/18) for example).  
The implementation detail is the underlying C library and for performance reason I understand that it is better to reuse the space allocated, making the type mutable.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [March 19, 2017, 12:17pm UTC](https://discourse.julialang.org/t/why-is-not-big-1-big-1/2750/5 "2017-03-19T12:17:54Z")

</div>

> [@mzaffalon](#):
>
> they should be immutable and === should work

No.

> [@mzaffalon](#):
>
> this has already been discussed (here for example).

That’s unrelated.

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [March 19, 2017, 1:15pm UTC](https://discourse.julialang.org/t/why-is-not-big-1-big-1/2750/6 "2017-03-19T13:15:59Z")

</div>

No to what? That numbers are immutable or that `===` should work?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [March 19, 2017, 1:37pm UTC](https://discourse.julialang.org/t/why-is-not-big-1-big-1/2750/7 "2017-03-19T13:37:01Z")

</div>

Both. They don’t need to be immutable and `===` doesn’t need to work the same as `==` for numbers.
