"The abs(X) function returns the absolute value of the numeric argument X.
Abs(X) returns NULL if X is NULL. Abs(X) return 0.0 if X is a string or
blob that cannot be converted to a numeric value. If X is the integer
-9223372036854775807 then abs(X) throws an integer overflow error since
there is no equivalent positive 64-bit two complement value."

* The int should be -9223372036854775808.

* Also, "return 0.0" should be "returns 0.0".

* Also, "two complement" should be "two's complement".

Minor typos aside, it's interesting that SQLite is nice enough to convert
integers strictly less than -1 * 2^63 to floats and then take the floating
absolute value.

This means that the only gap in the function's domain is at the sole
integer value -1 * 2^63.  One greater and SQLite gives you a value; one
less and SQLite gives you a value:

sqlite> select abs(-9223372036854775807);
9223372036854775807
sqlite> select abs(-9223372036854775808);
Error: integer overflow
sqlite> select abs(-9223372036854775809);
9.22337203685478e+18

Given that, and given SQLite's general philosophy of being flexible about
its inputs, would it make sense for SQLite to convert -1 * 2^63 to a float
and return the floating absolute value, as it does for (-1 * 2^63) - 1?

I can also see the arguments against that choice: users who were careful to
store a 64-bit integer into a field may be surprised when it gets converted
to a float when passed through abs().  You also have backward compatibility
considerations.

Thanks as always to drh and team for the awesome tool.

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

Reply via email to