Description
During the compilation of WebARKitLib with Emscripten, the following warning is triggered in src/AR2/selectTemplate.c:
C:/path/to/webarkit-org/jsartoolkitNFT/emscripten/WebARKitLib/lib/SRC/AR2/selectTemplate.c:279:41: warning: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
279 | k = (int)((float )j * rand() / (RAND_MAX + 1.0F));
| ^~~~~~~~ ~
Root Cause
The expression RAND_MAX + 1.0F forces the integer RAND_MAX (0x7fffffff) to be converted into a float. Since 2147483648 (2^31) cannot be represented exactly as a 32-bit single-precision float without potential loss of precision, the compiler issues this warning.
Proposed Solution
The calculation should be performed using double precision to ensure accuracy and resolve the implicit conversion warning.
Specifically, changing line 279:
-k = (int)((float )j * rand() / (RAND_MAX + 1.0F));
+k = (int)((double)j * rand() / ((double)RAND_MAX + 1.0));
Environment
Compiler: Emscripten (emcc)
File: lib/SRC/AR2/selectTemplate.c
Description
During the compilation of WebARKitLib with Emscripten, the following warning is triggered in
src/AR2/selectTemplate.c:Root Cause
The expression RAND_MAX + 1.0F forces the integer RAND_MAX (0x7fffffff) to be converted into a float. Since 2147483648 (2^31) cannot be represented exactly as a 32-bit single-precision float without potential loss of precision, the compiler issues this warning.
Proposed Solution
The calculation should be performed using double precision to ensure accuracy and resolve the implicit conversion warning.
Specifically, changing line 279:
Environment
Compiler: Emscripten (emcc)
File: lib/SRC/AR2/selectTemplate.c