编译双比较函数'IsAlmostEqual'时出现Emscripten错误 [英] Emscripten error when compiling double comparison function 'IsAlmostEqual'

查看:468
本文介绍了编译双比较函数'IsAlmostEqual'时出现Emscripten错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手使用emscripten,并在编译cpp文件时遇到错误。

I'm novice in using emscripten and encountered an error in compiling cpp file.

我有iae.cpp:

bool IsAlmostEqual(double A, double B)
{
  //http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
  long long aInt = reinterpret_cast<long long&>(A);
  if (aInt < 0) aInt = -9223372036854775808LL - aInt;
  long long bInt = reinterpret_cast<long long&>(B);
  if (bInt < 0) bInt = -9223372036854775808LL - bInt;
  return (std::abs(aInt - bInt) <= 10000);
}



我尝试使用emscripten编译:

I tried to compile it using emscripten:

emcc iae.cpp

但会生成以下警告和错误: p>

but it generates the following warnings and errors:

INFO     root: (Emscripten: Running sanity checks)
WARNING  root: java does not seem to exist, required for closure compiler. -O2 and above will fail. You need to define JAVA in ~/.emscripten
iae.cpp:5:27: warning: integer constant is so large that it is unsigned
    if (aInt < 0) aInt = -9223372036854775808LL - aInt;
                          ^
iae.cpp:7:27: warning: integer constant is so large that it is unsigned
    if (bInt < 0) bInt = -9223372036854775808LL - bInt;
                          ^
iae.cpp:8:13: error: use of undeclared identifier 'std'
    return (std::abs(aInt - bInt) <= 10000);
            ^
2 warnings and 1 error generated.
ERROR    root: compiler frontend failed to generate LLVM bitcode, halting

如何摆脱这些警告和错误,甚至可以编译 IsAlmostEqual()使用emscripten?

How to get rid of these warnings and errors and is it even possible to compile IsAlmostEqual() using emscripten?

推荐答案

看起来像你


  1. 缺少一个包含< cstdlib>

  2. 尝试使用64位值,这不是Javascript本身支持的。你可以这样做,但只是牺牲性能。有关指导,请参阅 https://github.com/kripken/emscripten/wiki/CodeGuidelinesAndLimitations

  1. Missed an include to <cstdlib>
  2. Try to use a 64 bit value, which is not natively supported by Javascript. You can do this BUT only at the expense of performance. Read https://github.com/kripken/emscripten/wiki/CodeGuidelinesAndLimitations for guidance.

这篇关于编译双比较函数'IsAlmostEqual'时出现Emscripten错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆