-- Demonstrates floating point error

with ada.text_io; use ada.text_io;             -- Library for text output
with ada.float_text_io; use ada.float_text_io; -- Library for floating point output
with ada.integer_text_io; use ada.integer_text_io;

with unchecked_conversion;
 
procedure one_v4  is 

    function convert is new unchecked_conversion(source => float, target => integer);

    point_01: constant float := 0.01;
    sum: float := 0.0;

    i, j: integer;

begin
    for i in 1 .. 100 loop 
        sum := sum + point_01; 
    end loop;

    put("point_01 in scientific notation: ");
    put(point_01);      
    new_line;

    put("point_01 formatted: ");
    put(point_01, fore => 1, aft => 9, exp => 0);  -- Formatted output is easier to read
    new_line;

    put("point_01 with more decimal places: ");
    put(point_01, fore => 1, aft => 25, exp => 0); -- Let's examine more decimal places
    new_line(2);

    put("sum formatted: ");
    put(sum, fore => 1, aft => 9, exp => 0);      
    new_line;

    i := convert(point_01);
    j := convert(sum);

    put(i, base => 2); new_line;
    put(j, base => 2); new_line;

    put(i, base => 16); new_line;
    put(j, base => 16); new_line;

end one_v4;