Package Verada.Vibe.Decimal_Digits
Verada.Vibe.Decimal_Digits: the decimal digits of a float for Vibe's format specs (Verada.Vibe.Formatting), correctly rounded as CPython's are: halves to even, on the exact binary value. Verada's body has them from its run time (C's snprintf); GNAT's stand-in computes them in Ada. Only the digits come from here: their layout is Formatting's.
Mode
type Mode is (Exponent, Fixed, Percent, Shortest);what the digits are: Python's 'e' (Precision + 1 significant digits), 'f' (the integer part's digits, then Precision more), '%' ('f' of the value times 100, rounded to a double as Python's is), and repr's (the fewest significant digits that read back)
Class
type Class is (Finite, Infinite, Not_A_Number);Room
function Room (How : Mode; Precision : Natural) return Long_Long_Long_Integer is
(case How is
when Exponent => Long_Long_Long_Integer (Precision) + 1,
when Fixed | Percent => Long_Long_Long_Integer (Precision) + 401,
when Shortest => 17);the room the digits need: a double's integer part has at most 309 digits
Convert
procedure Convert (X : Long_Float; How : Mode; Precision : Natural;
Item : out String; Count : out Positive; Point : out Integer;
Kind : out Class; Negative : out Boolean)
with Global => null,
Pre => Item'First = 1 and then Long_Long_Long_Integer (Item'Length) = Room (How, Precision),
Post => Count <= Item'Length
and then (for all I in 1 .. Count => Item (I) in '0' .. '9')
and then Point in -400 .. 400
and then (case How is
when Exponent => Count = Precision + 1,
when Fixed | Percent => Count > Precision and then Point = Count - Precision,
when Shortest => Count <= 17);the digits of X's magnitude, Item (1 .. Count), and Point, how many of them come before the decimal point (it may be 0 or less, or more than Count, for Exponent and Shortest: the decimal exponent is Point - 1); Kind is X's (for Percent, of X times 100), and Negative its sign bit (so -0.0 is negative). For a value that is not Finite there are no digits but Item (1) = '0'.