Type for large "float like" integers?

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…

1 Like

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

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

julia> setprecision(BigFloat, 8)

julia> parse(BigFloat, "4.35e435")
1 Like

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?

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> BigFloat(BigFloat("4.35e435", 8), 8192)

If you want to exactly represent integers times powers of 10, you could use 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.


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

[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 or GitHub - JuliaMath/DoubleFloats.jl: math with more good bits

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:

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

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.

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


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?

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, 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 BigInts — 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?

1 Like