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.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal