I can think of a very elegant solution to this whole ordeal, which is inspired by Perl's way of doing things: Have *two* division operators which have different behaviour and which look different so you can tell what will happen where they are used, regardless of their operand data types. Perl is loosely typed by default and so has elegant handling down to a fine art, having for example different operators for string and numerical comparisons, so you always know what will happen regardless of the operand data types.

So I propose for SQLite that any expression having '/' will cast both of its operands as reals and the result will be a real.

Also, any expression using instead 'DIV' will cast both of its operands as integers (truncating them if necessary, not rounding) and return an integer.

To go with that, 'MOD' will cast both operands as integers and return the integer modulus.

It works out visually, both 'word' operators use integers and the one 'symbol' operator uses reals.

Sure there's a difference, and while this should help an implementer, it is useful to users because it describes *behaviour*.

On a different matter ...

At 9:59 PM -0500 11/1/05, [EMAIL PROTECTED] wrote:
John Stanton <[EMAIL PROTECTED]> wrote:

 Users love such a number system because it is natural and works like the
 Arithmetic they learned in Grade School.

 I find the idea of dividing two integers stored in binary form and
 getting a gratuitous conversion to floating point ugly and potentially
 very annoying.

I admit that it has been 4 decades since I was in grade school,
but back in the 60's we were taught that 5/2 is 2.5.  Are they
teaching something different now?  Or have I misunderstood the
comment?

Well, if you want to know ...

In the youngest grades, such as kindergarten and grade 1 etc, they only work with whole numbers, such as when dividing up apples or oranges, so 5/2 is "2 with 1 remainder". Only in later grades do they start with fractional numbers, such as 5/2 is "2.5" or "2 and 1/2".

So young children actually get it both ways depending on their ages.

-- Darren Duncan

Reply via email to