RTL: Sqrt & Pow
This commit is contained in:
@@ -153,6 +153,16 @@ type
|
||||
[AstSignature('(number) -> number')]
|
||||
class function Sign(const Arg: TScalar): TScalar; static;
|
||||
|
||||
[TRtlExport('Sqrt', Pure)]
|
||||
[AstDoc('Returns the square root of a number.')]
|
||||
[AstSignature('(number) -> number')]
|
||||
class function Sqrt(const Arg: TScalar): TScalar; static;
|
||||
|
||||
[TRtlExport('Pow', Pure)]
|
||||
[AstDoc('Returns Base raised to the power of Exponent.')]
|
||||
[AstSignature('(number, number) -> number')]
|
||||
class function Pow(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
// --- DateTime ---
|
||||
|
||||
[TRtlExport('Now', Impure)]
|
||||
@@ -326,6 +336,20 @@ type
|
||||
class function Trunc_Ordinal_Ordinal(A: Int64): Int64; static;
|
||||
[TRtlExport('Trunc', Pure)]
|
||||
class function Trunc_Float_Ordinal(A: Double): Int64; static;
|
||||
|
||||
[TRtlExport('Sqrt', Pure)]
|
||||
class function Sqrt_Ordinal_Float(A: Int64): Double; static;
|
||||
[TRtlExport('Sqrt', Pure)]
|
||||
class function Sqrt_Float_Float(A: Double): Double; static;
|
||||
|
||||
[TRtlExport('Pow', Pure)]
|
||||
class function Pow_Ordinal_Ordinal_Float(A, B: Int64): Double; static;
|
||||
[TRtlExport('Pow', Pure)]
|
||||
class function Pow_Float_Float_Float(A, B: Double): Double; static;
|
||||
[TRtlExport('Pow', Pure)]
|
||||
class function Pow_Ordinal_Float_Float(A: Int64; B: Double): Double; static;
|
||||
[TRtlExport('Pow', Pure)]
|
||||
class function Pow_Float_Ordinal_Float(A: Double; B: Int64): Double; static;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@@ -536,6 +560,22 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TRtlFunctions.Sqrt(const Arg: TScalar): TScalar;
|
||||
begin
|
||||
var val: Double := Arg; // Implicit cast to Double handles both Ordinal and Float
|
||||
Result := TScalar.FromDouble(System.Sqrt(val));
|
||||
end;
|
||||
|
||||
class function TRtlFunctions.Pow(const Args: TArray<TDataValue>): TDataValue;
|
||||
begin
|
||||
if Length(Args) <> 2 then
|
||||
raise EArgumentException.Create('Pow requires 2 arguments (Base, Exponent).');
|
||||
|
||||
var baseVal: Double := Args[0].AsScalar; // Implicit cast
|
||||
var expVal: Double := Args[1].AsScalar; // Implicit cast
|
||||
Result := TScalar.FromDouble(System.Math.Power(baseVal, expVal));
|
||||
end;
|
||||
|
||||
// --- Date Constructors ---
|
||||
|
||||
class function TRtlFunctions.Now(const Args: TArray<TDataValue>): TDataValue;
|
||||
@@ -1024,4 +1064,34 @@ begin
|
||||
Result := System.Trunc(A);
|
||||
end;
|
||||
|
||||
class function TRtlFunctions.Sqrt_Ordinal_Float(A: Int64): Double;
|
||||
begin
|
||||
Result := System.Sqrt(A);
|
||||
end;
|
||||
|
||||
class function TRtlFunctions.Sqrt_Float_Float(A: Double): Double;
|
||||
begin
|
||||
Result := System.Sqrt(A);
|
||||
end;
|
||||
|
||||
class function TRtlFunctions.Pow_Ordinal_Ordinal_Float(A, B: Int64): Double;
|
||||
begin
|
||||
Result := System.Math.Power(A, B);
|
||||
end;
|
||||
|
||||
class function TRtlFunctions.Pow_Float_Float_Float(A, B: Double): Double;
|
||||
begin
|
||||
Result := System.Math.Power(A, B);
|
||||
end;
|
||||
|
||||
class function TRtlFunctions.Pow_Ordinal_Float_Float(A: Int64; B: Double): Double;
|
||||
begin
|
||||
Result := System.Math.Power(A, B);
|
||||
end;
|
||||
|
||||
class function TRtlFunctions.Pow_Float_Ordinal_Float(A: Double; B: Int64): Double;
|
||||
begin
|
||||
Result := System.Math.Power(A, B);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user