Re: Finding antilogarithm with Delphi


[ Delphi Forum ]

Posted by webmaster Guido

In Reply to: Finding the antilogarithm with Delphi posted by Lionel Joyner:

: The problem is that when I use the (Log10(X)) the results is the mantissa and when I inverse using (Power(10,X)) I get the mantissa.

: How does one handle the +/- characteristic in this perplexing situation so they get the real number?
------------------------------------

I don't quite understand what you mean, that's not what I get with my testcode:

- the result of Log10(X) gives the logarithm in base 10 of X, not only the "mantissa";
example: Log10(5000) gives 3,69897000433602

- when I use Power(10, X) I get 10 to the power X, not the "mantissa";
example: Power(10, 3) gives 1000

For my test, I used a form with two buttons and two editboxes:
- an Edit for what you called the "real number", named edNumber;
- and another Edit for the logarithm, named edLog.

// Calculate the logarithm with base 10 of a number X that 
// was entered in edNumber and display result L in edLog
procedure TForm1.btnCalcLogClick(Sender: TObject);
var
  L, X: real;
  ErrCode: integer;
begin
  Val(edNumber.Text, X, ErrCode); // input number
  L := Log10(X);                  // calculate logarithm
  edLog.Text := FloatToStr(L);
end;
// Calculate the antilogarithm with base 10 of a number L that 
// was entered in edLog and display result X in edNumber
procedure TForm1.btnCalcAntiLogClick(Sender: TObject);
var
  L, X: real;
  ErrCode: integer;
begin
  Val(edLog.Text, L, ErrCode);  // input logarithm
  X := Power(10, L);            // calculate antilogarithm
  edNumber.Text := FloatToStr(X);
end;

Does this clarify your problem? Please ask again if I understood you wrongly.



Related Articles and Replies:


[ Delphi FAQ ]