Re: [q-lang-users] Exponentiation operator
Brought to you by:
agraef
From: Rob H. <hub...@gm...> - 2006-06-16 19:22:19
|
Albert Graef wrote: > A related question is whether rational arithmetic should return an Int > instead of a Rational when the denominator of the result is 1. Rob, what > is your take on this? In your current implementation it will always > return a Rational, right? > > Albert > > Yes, currently a Rational is returned even if the value could be float. All the functions return a "normalised" value. Thus a simple way to implement the other behaviour is to change "normalisation" to reduce to Int when possible. There's a chance that some of my algorithms will need to be tweaked afterwards, as sometimes I assume in some private functions that a value is in the form (rat N D). Thus perhaps there should be separate "normalisers" for producing intermediate values, and for returning values to a the public interface. I think that the behaviour ought to follow the style of what you do with (^). There are pros and cons with either approach. On the one hand, always having a Rational gives you certainty of type. On the other hand, having a simpler type returned may be an advantage, especially when that's an intermediate value. Rob. |