SQLite Forum

SQLite 3.43.0 regression on REAL formatting with old MSVC compilers
Login

SQLite 3.43.0 regression on REAL formatting with old MSVC compilers

(1) By anonymous on 2023-09-14 15:50:24 [source]

Hello SQLite community,

We do embed SQLite in old/legacy devices (like Windows CE) with old Microsoft compiler like VS2005/VS2008/VS2010.

3.43 improves double arithmetic with long double and dekkerMul2() fallback algorithm. But, this is problematic for our builds. Updating the toolchain is not an option. Those targets also don't have long double support.

Troubleshooting the issue, I discovered that Microsoft compilers don't do double to unsigned 64bits conversion. The conversion is done on SIGNED 64bits.

https://stackoverflow.com/questions/3332440/safe-conversion-from-double-to-unsigned-64-bit-integer

SQLite 3.43.1 2023-09-11 12:25:57 4acd629be2bb593a2229bc95416120b600ecd828af596b26e62ac240a0ed45ad
msvc-1600 (32-bit)
sqlite> .testctrl uselongdouble
0
sqlite> select 1.1;
0.922337203685478
sqlite> .testctrl uselongdouble 1
1
sqlite> select 1.1;
1.1

we could use dynamic detection like
int CanCastDoubleToU64()
{
	double d = 1.1e19;
	u64 u = (u64)d;
	return (u&8000000000000000);
}
or add PRECOMPILER directives to workaround these compilers issues.

This would need to lower the precision checks with constants like

while( rr[0]<9.22e+17  ){
	exp -= 1;
	dekkerMul2(rr, 1.0e+01, 0.0);
}
in
SQLITE_PRIVATE void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){

Regards,

(2) By Richard Hipp (drh) on 2023-09-14 16:49:12 in reply to 1 [link] [source]

Do this for us, please:

  1. Visit https://sqlite.org/src/info/legacy-msvc-workaround
  2. Download a tarball or ZIP archive (to the right of "Downloads:")
  3. Build the new SQLite using your legacy compiler
  4. Report back on this forum thread whether or not the changes found on the branch check-in in (1) resolve your problem.

(3) By anonymous on 2023-09-15 08:25:10 in reply to 2 [link] [source]

Thanks for the patch.

Tested successfully against VS2008 and VS2010.

Regards,