Alessandro,
I now understand that you wanted a general approach to finding decimal digits of accuracy for an arbitrary specific number range, and I think that has now been answered.
But I said I would provide details about a closely-related problem, which is converting to decimal form and back. This is a much trickier subject than you would imagine. Consider 8-bit standard posits, which according to the Posit™ Standard (2022) can be converted to 2 decimals of accuracy and that 2-decimal number will convert back to the original posit. But consider this diagram for part of the range:
If you convert 1/8 = 0.125 to a 2-digit decimal, you have a tie between 0.12 and 0.13. By the "ties go to even" (banker's rounding) rule, you would choose 0.12; however, when you convert 0.12 back to a posit, you should get 15/128 = 0.1171875 as the closest posit representation, which is marked "oops" in the diagram. In this case, converting 1/8 to 0.13 will give correct behavior, but I'm still uncertain what the algorithm is for handling all such cases. It's not just posits, by the way; a similar problem can happen with floats.
This brings up an interesting advantage of posits over floats: compact formatting. The more extreme the magnitude, the greater the need to express an exponent instead of using the location of the decimal point, but the lower the number of decimals needed to express the value such that it converts back to the correct posit. I believe all 8-bit posits can be expressed using only six characters, in human-readable decimal. For example, starting with minPos = 1 / 16777216:
00000001 +6e–8
The point at which to switch from e notation to movable decimal point is a matter of taste, but all of those fit in just five characters. The next one requires the maximum of six characters:
00001101 +.0015 That's the first one that requires two decimal digits.
Then when you get to the range 1/16 to 16 where the accuracy is highest, you have space for two decimals where needed:
and once you get to large magnitudes, you can go back to e notation:
.
.
.
01110100 +1e3
01110101 +1.5e3 That's the last one that requires two decimal digits.
I haven't worked out what the minimum number of characters is for standard 16-bit and 32-bit posits yet, but I'm pretty sure it is more compact than for IEEE floats of the same precision. as the result of tapered accuracy making room for the e notation.
John