On May 26, 2011, at 2:54 AM, Jan Hudec wrote: > Gotcha! No, it's not. -1-x is equivalent, but -x-1 is not: > > sqlite> select -1-(1<<63), -(1<<63)-1; > 9223372036854775807|9.22337203685478e+18 > > Besides my point was not that it's not possible, but that it would > be more readable with dedicated operator.
Yes. The fact that a negative number (-1) minus a large positive number (1 << 63) results in a positive number does not seem to be in concert with the goal of handling arithmetic overflows sensibly. This is especially egregious in the second case where the result of negating a large positive number and subtracting one is positive AND REAL (double float). Ideally SQLite would guarantee one of (in my order of preference): 1) Integer operations that overflow 64 bits behave as wrapped twos complement, i.e., they return the low 64 bits of the infinite precision twos complement integer result 2) Integer operations that overflow 64 bits result in floating point values that approximate the result with the precision of IEEE double 3) Integer operations that overflow have no guaranteed result I think option 2 is what SQLite is supposed to do (per the release notes), but is failing in both cases of this example. e _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users