Domanda

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?

È stato utile?

Soluzione

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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top