Hi all,

This is not really a SQLite issue, but the only solution I found out so far 
consists in modifying SQLite sources.

Maybe someone here is able to clarify the following mystery... 

---
SQLite shell output:

R:\>sqlite NUL "select 99990.1;"
99990.1


JSDB (www.jsdb.org) output:

js>var db = new SQLite();
js>db.exec("select 99990.1", function(r){writeln(r)});
99990.1=99990.1000000001
true
---

[Same rounding error with a couple of other "short" reals]

AFAIK, JSDB does use the SQLite library properly.

Technically, I can not figure out why sqlite3:sqlite3VXPrintf() behaves 
differently if embedded in the SQLite shell or in JSDB.

In this particular case, "realvalue" values start to diverge slightly from the 
"10.0" loop:

---
if( realvalue>0.0 ){
  while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
  while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
  
  while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }  <--
  
  while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; }
  while( realvalue<1.0 ){ realvalue *= 10.0; exp--; }
---    

Adding intermediate exp power(s) of 2 (between 8 and 1) in the lines above does 
fix the problem, e.g.:

(...)
if( realvalue>=1e4 && exp<=350 ){ realvalue *= 1e-4; exp+=4; }
(...)

However I still do not know why the same code/input/compiler options etc. lead 
to slightly different results.

Any hint welcome!

Thanks in advance.

Regards,
Etienne
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to