Simon Slavin wrote:
On 12 May 2013, at 11:07am, Paul van Helden <p...@planetgis.co.za> wrote:

SELECT 1/2 returns 0 which to me is a little odd, but I see from this page:
http://www.sqlite.org/sqllogictest/wiki?name=Differences+Between+Engines
that most other engines do the same.

A few year ago I was debugging ridiculous behaviour in a huge app and found to 
my dismay the same problem in C.  Evaluate 1/9 and you get zero.  You have to 
use 1.0/9 or 1/9.0 for a floating point result.  And hey presto:
That is the correct behavior. 1/9 is integer division. No remainder and no automatic conversion to float. It is expected that you would assign the result to an integer variable.

float x = 1/9;

first we do the integer division: 1/9 =0
then we convert to float and do the assignment

Not a bug. Most modern compilers would actually do the 1/9 division prior to compiling your program.

If you want floats, you have to specify floats. If you want integers, you have to specify integers. The compiler has no way to know which you want.

Just get in the habit of always adding a .0 if you want float constants.

--
Engineer for hire
Contract management, administration, training
http://www.seiner.com/engineer/resume.pdf


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to