On Tuesday, 11 July, 2017 07:24, David Raymond <david.raym...@tomtom.com> said:


> Not to be the new guy here, but would someone be so good as to explain why
> no one else is panicking that the modulo operator is horrifically broken?
> In http://www.sqlite.org/lang_expr.html it just says:
> "The operator % outputs the value of its left operand modulo its right
> operand."
> 
> There's nothing in there that says anything about requirements for the
> operands to be integers or about quietly rounding the results on you etc.
> 
> sqlite> select 1.4444 % .001;
> 1.4444 % .001
> NULL
> Shouldn't that be .0004?
> 
> sqlite> select 1.4444 % 2;
> 1.4444 % 2
> 1.0
> Why is this not 1.4444? This is worse than the NULL by blatantly giving a
> wrong answer and letting you think it succeeded.

You are correct.  The modulus operator only works on integers, not on floating 
point.  The operands are converted to integer and the return value is the 
result of that integer modulus operation.  This should probably be noted in the 
documentation for the % operator.

SQLite does not natively implement the fmod(x, y) function from the platform 
math library.  You would have to add that yourself either as a loadable or 
builtin extension.




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

Reply via email to