# Type computation: numerical type with twice more bits

**URL:** <https://discourse.julialang.org/t/type-computation-numerical-type-with-twice-more-bits/77000>\
**Category:** General Usage\
**Tags:** numbers, integer-overflow\
**Created:** [February 23, 2022, 11:58pm UTC](https://discourse.julialang.org/t/type-computation-numerical-type-with-twice-more-bits/77000 "2022-02-23T23:58:56Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [February 24, 2022, 9:42am UTC](https://discourse.julialang.org/t/type-computation-numerical-type-with-twice-more-bits/77000/4 "2022-02-24T09:42:47Z")

</div>

> [@greatpet](#):
>
> I don’t want BigInt, for efficiency reasons.

Then note on this advice:

> [@DNF](#):
>
> In most cases [widen](https://docs.julialang.org/en/v1/base/base/#Base.widen) should do what you want.

I checked and it does widen up to Int128, but then to BigInt, and Float64 to BigFloat. Inherently there’s nothing wrong with going to Int256 or higher (or even just to Int64 before BigInt), it’s just that Julia doesn’t have those types, but a package does up to Int1024 if I recall.

It’s

> defined so that arithmetic operations + and - are guaranteed not to overflow nor lose precision for any combination of values that type x can hold.

actually you only need to widen by 1 bit for that, if you had such a type. For `a * b` you need a-plus-b-number-of-bits, or double them when same type, what widen does. `^` and `<<` are problematic operators.

That’s the short summary of my longer (not, yet, implemented proposal):

> [@Potential solution to the overflow problem; 64-bit considered harmful, 32- or 21-bit better](https://discourse.julialang.org/t/potential-solution-to-the-overflow-problem-64-bit-considered-harmful-32-or-21-bit-better/69918):
>
> We can implement FastIntegers.jl, faster than the current default Int64 and eliminate overflows from the language by leveraging Julia’s type system, and no hardware support is needed. As a package it of course doesn’t change the language itself, it would be a prototype, or actually very useful as such, but even better if integrated into the language. That could happen for Julia 2.0 but not if people are against the idea. If we consider even very simple functions: double(x) = 2x then it’s not …

---

_[View the full topic](https://discourse.julialang.org/t/type-computation-numerical-type-with-twice-more-bits/77000)._
