[fpc-pascal] Generics: Error: Can't determine which overloaded function to call
LacaK
lacak at zoznam.sk
Wed Sep 18 11:46:52 CEST 2019
Work-around which produces good assembler without writting/reading
intermediate variables:
class function T2DPoint.Sqr(value: T): T; static; inline;
begin
Result := value*value;
end;
function T2DPoint.Distance(P: T2DPoint): Single; inline;
begin
Result := Sqrt(Sqr(x-P.x) + Sqr(y-P.y));
end;
>
> Is there other solution as:
>
> function T2DPoint.Distance(P: T2DPoint): Single;
> var dx,dy: T;
> begin
> dx := x-P.x;
> dy := y-P.y;
> Result := Sqrt(dx*dx + dy*dy);
> end;
>
> (for integer operations Sqr() is implemented as "value*value", so
> there is no difference (compared to above mentioned implementation)
> but for floating point operations there is called internal function
> "fpc_in_sqr_real" which is IMO implemented in smarter way that
> "value*value" (I can not find where/how is implemented)?)
>
> TIA
>
> -Laco.
>
More information about the fpc-pascal
mailing list