In risk of asking the obvious, I wonder if the following division should be 
considered correct:

  | Query             | Result Value | Result Type    | OK?
-----------------------------------------------------------
1 | SELECT 5 / 2;     | 2            | SQLITE_INTEGER | No?
2 | SELECT 5.0 / 2;   | 2.5          | SQLITE_FLOAT   | Yes
3 | SELECT 5 / 2.0;   | 2.5          | SQLITE_FLOAT   | Yes
4 | SELECT 5.0 / 2.0; | 2.5          | SQLITE_FLOAT   | Yes

The query in question is Query 1. Is the returned integer result correct or 
should it not better return the 2.5 float value instead?

I understand that this probably boils down to integer arithmetics, but the 
decimals dropping can cause severe rounding errors if SQLite stores an integer 
number without further warning like in:

  CREATE TABLE t (a REAL, b REAL);
  INSERT INTO t VALUES (5, 2);

Then the query

  SELECT a / b FROM t;

returns wrong results, even though both colums are declared as REAL.

In my opinion, any division which can not be represented as an integer should 
return a float value.

What do you think?

Regards,

Ralf

Reply via email to