Division from derived integer type to a derived floating point type

Hi, so I have these generic formal types:

generic
	type TInteger is range <> or use Integer;
	type TFloat is digits <> or use Float;
package Fractions_ADT is

with later the type private type “Fractions” defined. But I don’t know exactly how to transform a fraction to a TFloat. This

function To_Float (A: Fractions) return TFloat is (TFloat’(A.Numerator / A.Denominator));

doesn’t work. I don’t know if TFloat automatically gets a constructor from all integer-like types… or do I have to convert each operand to Float before ?

Try:

function To_Float (A: Fractions) return TFloat is 
   (TFloat(A.Numerator) / TFloat(A.Denominator));

No because A’s components both have a TInteger type, not TFloat.

Sorry, I didn’t catch that you originally used qualified expressions instead of type conversions so I didn’t have it correct before. I updated it. Using type conversions it works:

with Ada.Text_IO; use Ada.Text_IO;

procedure jdoodle is
    type Fractions is record
        Numerator   : Integer;
        Denominator : Integer;
    end record;
    
    type TFLoat is new Float;
    
    function To_Float (A: Fractions) return TFloat is 
        (TFloat(A.Numerator) / TFloat(A.Denominator));
        
    F : Fractions := (Numerator => 1, Denominator => 3);
    T : TFLoat    := To_Float(F);
begin
    Put_Line("Result = " & T'Image);
end jdoodle;

Output:

Result =  3.33333E-01

gcc -c jdoodle.adb
gnatbind -x jdoodle.ali
gnatlink jdoodle.ali -o jdoodle