From: Libor S. <li...@gm...> - 2008-07-08 14:04:55
|
On Tue, 08 Jul 2008 13:18:16 +0100, Albert Graef <Dr....@t-...> wrote: > A division operator which returns ints only if x divides y? I don't > think that this is a good idea, as you never know which type is > returned. The rationale behind / is precisely that you *always* get a > double result, same with '^'. That's the Algol philosophy and I think > it's good; I won't change it. > > div/mod is another business; as long as they work consistently with the > integer div/mod and they cover all appropriate cases including rationals > I'm willing to add the extensions. > > Albert > OK, fair enough. I was working up to the "mad" idea which is probably too revolutionary and upsetting to everyone. The idea is that all the current numeric types become transparent (hidden) to the user. Promotions take place automatically (in the background) whenever a loss of information would otherwise occur, such as: int becoming too big -> bigint x div y -> rational (if y does not divide x) sqrt (-2) -> complex and demotions too: bigint that fits into an int -> int rational that simplifies to an int or bigint -> int or bigint complex with imaginary part == 0 -> real The hidden old style type would then be used only for deciding how to present the result. Also, replace doubles with rationals. (All numbers with limited precision are de facto rationals anyway). For pragmatic reasons place some limit on the size of the bigints and raise an exception when it is reached. I guess to really fly, this would need to be taken up by the processor manufacturers, to add rational instructions. The beauty of this scheme is that you could then get away with having just ::number type and nothing else and use only one common code for any calculations, instead of the current, frankly, mess. Libor |