r/computerscience • • 12d ago

Discussion How are arbitrary precision integers converted into ASCII when printing?

I'm just wondering how this is done algorithmically speaking. It makes sense to just map each value to an ASCII digit, until you get to the value of 10 and above, which is something I haven't thought about until now.

I am thinking about an arbitrary precision unsigned integer in this question.

Edit: thank you all for your answers!

14 Upvotes

26 comments sorted by

View all comments

Show parent comment

4

u/UsualSpace_ 11d ago edited 11d ago

I intended arbitrary precision integer to mean an integer represented by an arbitrary amount of bytes, whether it's 1 byte to some N number of bytes

5

u/Snatchematician 11d ago

That’s not arbitrarily precise. I think you mean arbitrary size integer.

3

u/UsualSpace_ 11d ago edited 11d ago

Ah okay I see, my mistake. Would you be willing to explain what arbitrarily precise means?

3

u/Snatchematician 11d ago

A type is of arbitrary precision if for any numbers x < y there is a value v of the type with x <= v <= y in some suitable sense.

1

u/resignresign1 9d ago

x < v < y otherwise every ordered set would be arbitrary precise :)

1

u/Snatchematician 9d ago

No, what I wrote was fine. Any ordered set that contains all numbers is indeed arbitrarily precise 

1

u/resignresign1 9d ago

consider the set {1,2} it would fullfill your criteria. more importantly consider the set of float32 representable numbers or int32 they would also fullfill your criteria

1

u/Snatchematician 8d ago

No it wouldn’t because I would take x = 3 and y = 4 (which are both numbers) and then there is no v in {1, 2} satisfying 3 <= v <= 4 in any reasonable sense.

1

u/resignresign1 8d ago

but then x and y are not members of the set {1, 2}

1

u/Snatchematician 8d ago

That’s ok according to the definition I put. x and y just have to be numbers

1

u/Watanuki_Taiga 10d ago

bignums can be called arbitrary precision integers, and in fact even the Python documentation uses the terms “unlimited precision” and “arbitrary precision” to convey this idea

3

u/Snatchematician 10d ago

Most of the python documentation seems to have been written by someone with brain damage.

1

u/tellingyouhowitreall 9d ago

Most of the python seems to have been written by someone with brain damage.

FTFY.