Emscripten error when compiling double comparison function 'IsAlmostEqual'

萝らか妹 提交于 2019-12-11 19:09:28

问题


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

I have 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);
}

I tried to compile it using emscripten:

emcc iae.cpp

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

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


回答1:


Seems like you

  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.


来源:https://stackoverflow.com/questions/21489197/emscripten-error-when-compiling-double-comparison-function-isalmostequal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!