# Type for large "float like" integers?

**URL:** <https://discourse.julialang.org/t/type-for-large-float-like-integers/107454>\
**Category:** General Usage\
**Tags:** numbers\
**Created:** [December 11, 2023, 4:07pm UTC](https://discourse.julialang.org/t/type-for-large-float-like-integers/107454 "2023-12-11T16:07:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [December 11, 2023, 4:07pm UTC](https://discourse.julialang.org/t/type-for-large-float-like-integers/107454/1 "2023-12-11T16:07:34Z")

</div>

Out of curiosity, is there a provided primitive type to represent a very large integer number with a fixed precision (e.g. 64), for example for an integer like `4.35e435` ?  
Obviously the information about this monster number needs only a few bits…

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [December 11, 2023, 4:10pm UTC](https://discourse.julialang.org/t/type-for-large-float-like-integers/107454/2 "2023-12-11T16:10:01Z")

</div>

FixedPointNumbers.jl is used commonly in Images.jl ecosystem. Perhaps you could then separate out the scaling factor.

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [December 11, 2023, 4:27pm UTC](https://discourse.julialang.org/t/type-for-large-float-like-integers/107454/3 "2023-12-11T16:27:45Z")

</div>

Isn’t this just `BigFloat` with small significand size? Like this:

```julia-repl
julia> setprecision(BigFloat, 8)
8

julia> parse(BigFloat, "4.35e435")
4.35e+435

```

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [December 11, 2023, 4:39pm UTC](https://discourse.julialang.org/t/type-for-large-float-like-integers/107454/4 "2023-12-11T16:39:52Z")

</div>

> [@sylvaticus](#):
>
> Obviously the information about this monster number needs only a few bits…

Give more info. What is the set of exponents you’re interested in, for a start? Are you interested in all integral exponents in some range, or would, e.g., every other integer in the range suffice? Do you need only large exponents, or do you need small exponents, too?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 11, 2023, 4:46pm UTC](https://discourse.julialang.org/t/type-for-large-float-like-integers/107454/5 "2023-12-11T16:46:18Z")

</div>

> [@nsajko](#):
>
> Isn’t this just `BigFloat` with small significand size? Like this:
> 
> ```julia-auto
> julia> setprecision(BigFloat, 8)
> 8
> 
> julia> parse(BigFloat, "4.35e435")
> 4.35e+435
> 
> ```

No, because `BigFloat` is a binary floating-point type — it exactly represents **integers multiplied by powers of two** , not powers of ten. In your example, by using 8 bits of precision it is actually rounded to about `4.30406e435`, as you can see by going to higher precision:

```julia-auto
julia> BigFloat(BigFloat("4.35e435", 8), 8192)
4.350406043907076599027172294984063931582175698421177426277981559834668315511897632097209626442962420945007481220187833977855393785055645523891838249009686637569733842595809486538543920313942826648018161496966740863244346829749014342611725090936881387727790215531588567299452398147650879974387007788383070437401380828605870923890564989245238502998217099064749190074411637725771063539325891121077700907115511632720097397795673644327763968e+435

```

If you want to exactly represent integers times powers of 10, you could use [decimal floating point](https://en.wikipedia.org/wiki/Decimal_floating_point), e.g. as implemented by DecFP.jl. For example, `4.35e435` is exactly represented by the `Dec128` type in DecFP, via `n = d128"4.35e435"`. (This exponent overflows the `Dec64` or `Dec32` types, which give `Inf`.)

Of course, the real question is what do you want to _do_ with this kind of number. What operations you want to support will determine the characteristics of the type that you want.

---

<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:** [December 11, 2023, 4:47pm UTC](https://discourse.julialang.org/t/type-for-large-float-like-integers/107454/6 "2023-12-11T16:47:45Z")

</div>

I think you can use Dec128 (It’s only twice the memory you wanted):

> **[GitHub - JuliaMath/DecFP.jl: Julia IEEE decimal floating-point via the Intel...](https://github.com/JuliaMath/DecFP.jl)**
>
> Julia IEEE decimal floating-point via the Intel decimal-float library

[My question, why do you need this large? Can use use Unitful.jl or something? And just Int64 or even Int32?]

My first thought was Float128: [GitHub - JuliaMath/Quadmath.jl: Float128 and libquadmath for the Julia language · GitHub](https://github.com/JuliaMath/Quadmath.jl) or [GitHub - JuliaMath/DoubleFloats.jl: math with more good bits · GitHub](https://github.com/JuliaMath/DoubleFloats.jl)

The former has the scale, but not (decimal) precision, and the latter has only the binary precision too, but no extra scale. There’s one other binary extended float package, very fast for varying precisions, but like the double double trick it doesn’t add scale, also is in binary.

but I think they do NOT work, nor BigFloat:

> [@nsajko](#):
>
> Isn’t this just `BigFloat` with small significand size? Like this:

Yes and no, it may look similar, but will not be exactly 4.350000…

> [@mkitti](#):
>
> [FixedPointNumbers.jl](https://juliahub.com/ui/Packages/FixedPointNumbers) is used commonly in [Images.jl](https://juliahub.com/ui/Packages/Images) ecosystem.

I think also it is only binary based, not decimal-based fixed point. Not a lot of people asking for decimal-based fixed point I think.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 11, 2023, 4:52pm UTC](https://discourse.julialang.org/t/type-for-large-float-like-integers/107454/7 "2023-12-11T16:52:27Z")

</div>

> [@mkitti](#):
>
> [FixedPointNumbers.jl](https://juliahub.com/ui/Packages/FixedPointNumbers) is used commonly in [Images.jl](https://juliahub.com/ui/Packages/Images) ecosystem. Perhaps you could then separate out the scaling factor.

A fixed-point number with a (variable exponential) scaling factor is also known as “floating point”. 😉

---

<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:** [December 11, 2023, 5:06pm UTC](https://discourse.julialang.org/t/type-for-large-float-like-integers/107454/8 "2023-12-11T17:06:33Z")

</div>

Is it, or only when the _point_ is floating (potentially)? You should know, I think you mean it as a joke.

Do you know if we have a _decimal_-based _fixed_-point type?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [December 11, 2023, 5:32pm UTC](https://discourse.julialang.org/t/type-for-large-float-like-integers/107454/9 "2023-12-11T17:32:34Z")

</div>

> [@sylvaticus](#):
>
> represent a very large integer number with a fixed precision (e.g. 64)

This really isn’t enough to go on here — that “represent” is doing a lot of work there. There’s an infinite number of ways in which you can choose what a bucket of 64 bits mean. It reminds me of this recent [blog post on what the largest “representable” finite number might be](https://tromp.github.io/blog/2023/11/24/largest-number), but it’s pretty fatuous as you can define the representation to be anything that you can write down — that’s kinda the point.

So you really do need to specify what you want here. Either you want `BigInt`s — in which you store the integer exactly — or you want some _truncated_ representation. And once you decide you’re not going to store the integer exactly, there are a whole host of choices and tradeoffs that come along. If you store, say, only X significant digits: are those base 2? Or base 10? How big is X? How big do you need the exponent to go?
