Re: [q-lang-users] Exponentiation operator
Brought to you by:
agraef
From: Rob H. <hub...@gm...> - 2006-06-16 19:13:50
|
I would prefer either: (1) Always a float, or (2) A value of a type as simple as possible (up to the simplicity of the arguments perhaps): thus Int if possible, otherwise Rational if possible, otherwise Real if possible, otherwise (perhaps) Complex (e.g. (-1)^(1/2) would be complex). That is, I think either (1) no attempt at all should be made to return an exact value in a suitable type; a Float should be returned where possible (i.e. where defined and Real), or (2) a thorough attempt should be made. With (2), I would like to see (1 over 100)^(1 over 2) return (1 over 10). I would also expect the algorithm for (2) know that (N over 1) is an integer. On the other hand, I would not expect the algorithm to recognise that e.g. 0.5 = 1/2. It's fair for the algorithm to assume that a value expressed in a given inexact type can not be expressed exactly as a simpler type. [Perhaps there should be operators to do both.] When both (1) and (2) produce values, those values should be "equal" (in some sense; the problem is of course that you can't rely on testing equality of floats). That's quite a tall order as X^(1/N) has N complex values, so great care would need to be taken in choosing the "principal value". One possibility for the algorithm is to (a) first find a complex value, then (b) attempt a series of simplifications somehow. That doesn't really answer the question does it?? Rob. |