我需要将值分配给线性,但是当我检查它时,结果是错误的。表达式1/exp( 2.30258509299 * (abs(dB)/20) )
的结果为0,063095734448(是正确值),但线性为-3,6854775808e + 4863,n为1,805186914e-307。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure OnCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.OnCreate;
var dB: integer;
linear: extended;
n: Double;
begin
dB := -24;
linear := 1/exp( 2.30258509299 * (abs(dB)/20) );
n := 0.063095734448;
showmessage(inttostr(db));
end;
end.
我在做什么错,以及如何获得正确的值?
注意:为了评估表达式,我使用了调试器的“评估/修改”命令。
[最有可能您启用了编译器优化,并且编译器认识到已将变量linear
和n
分配给了变量,但随后从未读取过。因此,在分配这些变量后,编译器无需保留这些变量。
尝试此代码
linear := 1/exp( 2.30258509299 * (abs(dB)/20) );
ShoewMessage(linear);