TRUNC and ROUND functions

Can use TRUNC or ROUND functions in expression?

example:

  • expression: ROUND(2.9)
  • result: 3

By default, the engine has ceil, floor, and frac functions (see documentation). But you can add your own function as a descendant.

I share my sample of final solution:

unit JPF.Analytix;
{ 20240411 omarperezh,
how to use: add in uses JPF.Analytix
sample: myround(2.5)=3, myround(2.4)=2 }

interface

uses
Base.Types,
Base.Assemblies,
Analytix.Functions;

Type
///


/// MyRound function
///

TMyRound = class sealed(TRealElementaryFunction)
protected
function GetName(): string; override;
function Func(const x: TFloat): TFloat; override;
public
class function IsRealized: boolean; override;
end;

procedure InitializeAssembly;

implementation

procedure InitializeAssembly;
begin
TClassFinder.InstantiateClass(TMyRound);
end;

{ TMyRound }

function TMyRound.Func(const x: TFloat): TFloat;
begin
result := ROUND(x);
end;

function TMyRound.GetName: string;
begin
result := 'myround';
end;

class function TMyRound.IsRealized: boolean;
begin
result := true;
end;

initialization

InitializeAssembly;

end.