Jump to content
Janilabo

4 simple & small math functions

Recommended Posts

Included example..

 

// Returns the opposite number of i. (-9999 to 9999 OR 9999 to -9999 [- <=> +])
function Opposite(i: Integer): Integer;
begin
 Result := (i * -1);
end;

// Returns the negative number of i. (-9999 to -9999 OR 9999 to -9999 [+/- => -])
function Negative(i: Integer): Integer;
begin
 Result := (IAbs(i) * -1);
end;

// Returns the opposite number of e. (-999.9 to 999.9 OR 999.9 to -999.9 [- <=> +]) 
function OppositeE(e: Extended): Extended;
begin
 Result := (e * -1);
end;

// Returns the negative number of e. (-999.9 to -999.9 OR 999.9 to -999.9 [+/- => -]) 
function NegativeE(e: Extended): Extended;
begin
 Result := (Abs(e) * -1);
end;

begin           
 WriteLn('Opposite "-999": ' + IntToStr(Opposite(-999)));
 WriteLn('Negative "999": ' + IntToStr(Negative(999)));  
 WriteLn('Opposite "999": ' + IntToStr(Opposite(999)));
 WriteLn('Negative "-999": ' + IntToStr(Negative(-999))); 
 WriteLn('');
 WriteLn('OppositeE "-999.99": ' + FloatToStr(OppositeE(-999.99)));
 WriteLn('NegativeE "999.99": ' + FloatToStr(NegativeE(999.99)));
 WriteLn('OppositeE "999.99": ' + FloatToStr(OppositeE(999.99)));
 WriteLn('NegativeE "-999.99": ' + FloatToStr(NegativeE(-999.99)));
end.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...