SQLite Forum

Bug: MSVC uses intrinsic versions of ceil and floor for floating-point modes precise and fast (diagnosed)
Login
I post the following as clues resulting from my investigation, not as a solution.

If these two functions definitions follow #include <math.h>:<code>
  static double vsCeil( double a ) { return ceil(a); }
  static double vsFloor( double a ) { return floor(a); }
</code>and the VS20{17,19} choking lines:<code>
    MFUNCTION(ceil,              1, ceil,      ceilingFunc ),
    MFUNCTION(ceiling,           1, ceil,      ceilingFunc ),
    MFUNCTION(floor,             1, floor,     ceilingFunc ),
</code>are replaced with:<code>
    MFUNCTION(ceil,              1, vsCeil,      ceilingFunc ),
    MFUNCTION(ceiling,           1, vsCeil,      ceilingFunc ),
    MFUNCTION(floor,             1, vsFloor,     ceilingFunc ),
</code>, then sqlite3.c compiles under VS2019 without producing the errors reported by the OP. Why this is remains a mystery to me.  The next line of code:<code>
    MFUNCTION(trunc,             1, trunc,     ceilingFunc ),
</code>compiles fine, and as far as I can see (while looking at preprocessor output with the same preprocessing options and definitions as for the failing compile), the ceil, floor and trunc functions are declared identically. (ie:<code>
      __declspec(dllimport) double    __cdecl ceil(  double _X);
      __declspec(dllimport) double    __cdecl floor(  double _X);
      __declspec(dllimport) double __cdecl trunc(  double _X);
)</code>. Yet replacing 'ceil' or 'floor' in the 3 failing lines with 'trunc' also eliminates the VS2019 complaints (while being mathematically incorrect.)

It's enough to make me wonder if those functions are resolving to an FPU intrinsic or some such goofiness, such that their names do not resolve to the address of an executable function.  I'll have to look into this further.