编译双重比较函数'IsAlmostEqual'时出现Emscripten错误

时间:2014-01-31 20:13:31

标签: c++ emscripten

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

我有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编译它:

emcc iae.cpp

但它会产生以下警告和错误:

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

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

1 个答案:

答案 0 :(得分:1)

似乎和你一样

  1. 错过了包含<cstdlib>
  2. 尝试使用64位值,Javascript本身不支持该值。你可以这样做,但这只会牺牲性能。请阅读https://github.com/kripken/emscripten/wiki/CodeGuidelinesAndLimitations以获取指导。