[EMAIL PROTECTED] wrote:

Joe Wilson <[EMAIL PROTECTED]> wrote:
I've found a potential problem - round() is not a good substitute for the old integer truncation.

Consider the previous Sqlite3 behavior:

 sqlite> select 15/8;
 1
 sqlite> select round(15.0/8.0);
 2

Can you recommend or provide a new function that performs correct
integer trunction?


I think the current code in CVS allows you to do this with

  CAST( 15.0/8.0 AS integer )

But I admit I need to test that case more thoroughly.
--
D. Richard Hipp <[EMAIL PROTECTED]>


Assuming the bitwise operators always work with integers as they do now (I don't think it makes much sense to OR two floating point numbers together), which is to truncate real arguments to integers before performing the operation, you can truncate any real value to an integer by ORing it with 0, or double complementing it like this.

select (15.0/8.0)|0;
select ~~(15.0/8.0);

both of these expressions return the truncated value, 1.

This also avoids the conversion of the values to text that round() does.

HTH
Dennis Cote

Reply via email to