NaN 根据 Python 启动给出错误?

发布于 2024-09-27 14:56:49 字数 514 浏览 0 评论 0原文

我正在使用 Python4Delphi 将 Python 嵌入到 Delphi 程序中。版本:Python 2.6.4、Delphi 2009、Windows XP。

导入 json 时,Delphi 程序因 EInvalidOp 崩溃。 行

NaN, PosInf, NegInf = float('nan'), float('inf'), float('-inf')

我跟踪它到json.decoder 中的

。果然,命令 float('nan') 在嵌入 Delphi 程序的 Python 中运行时会引发 EInvalidOp。当在命令行 Python 中执行时(相同的安装),它只返回 nan。

你知道Python标准启动和嵌入式启动之间有什么区别可能会导致这样的错误吗?

I am using Python4Delphi to embed Python in a Delphi program. Versions: Python 2.6.4, Delphi 2009, Windows XP.

The Delphi program crashes with EInvalidOp when importing json. I tracked it to the line

NaN, PosInf, NegInf = float('nan'), float('inf'), float('-inf')

in json.decoder.

Sure enough, the command float('nan') raises an EInvalidOp when run inside Python embedded in the Delphi program. When executed in the command line Python (same installation) it simply returns nan.

Any idea what is the difference between the Python standard startup and that of the embedded one that may result in such an error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弄潮 2024-10-04 14:56:49

这很可能是因为 Python 使用了与 Python 不同的 8087 控制字 (CW) 设置德尔福。

尝试这种代码:

var
  OldControlWord: Word;
begin
  OldControlWord := Get8087CW();
  Set8087CW($133F);
  try
    // perform your Python code here
  finally
    Set8087CW(OldControlWord);      
  end;
end;

请参阅我的 有关 Delphi 中的 8087 CW 的博客文章,了解 133F 美元价值的更详细说明。
它需要 T8087Precision 类型的 JCL (位于Jcl8087 单元)。

——杰罗恩

This is most likely that Python uses a different 8087 control word (CW) setting than Delphi.

Try this kind of code:

var
  OldControlWord: Word;
begin
  OldControlWord := Get8087CW();
  Set8087CW($133F);
  try
    // perform your Python code here
  finally
    Set8087CW(OldControlWord);      
  end;
end;

See my blog article on the 8087 CW in Delphi for a more detailed explanation of the $133F value.
It needs the JCL for the T8087Precision type (which is in the Jcl8087 unit).

--jeroen

绝影如岚 2024-10-04 14:56:49

我使用以下内容:
$1332 是 delphi 的默认值。
$1232 是处理 Python Issue 9980 的值。

procedure MaskFPUExceptions(ExceptionsMasked : boolean);
begin
//  if ExceptionsMasked then
//    Set8087CW($1332 or $3F)
//  else
//    Set8087CW($1332);
  if ExceptionsMasked then
    Set8087CW($1232 or $3F)
  else
    Set8087CW($1232);
end;

I use the following:
$1332 is the delphi default.
$1232 is the value to deal with Python Issue 9980.

procedure MaskFPUExceptions(ExceptionsMasked : boolean);
begin
//  if ExceptionsMasked then
//    Set8087CW($1332 or $3F)
//  else
//    Set8087CW($1332);
  if ExceptionsMasked then
    Set8087CW($1232 or $3F)
  else
    Set8087CW($1232);
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文