[phobos] std.complex: ready for Phobos?

Lars Tandle Kyllingstad lars at kyllingen.net
Tue Apr 20 02:06:19 PDT 2010


Does Complex!BigInt (or Complex!int, for that matter) *ever* make sense? 
  I mean, yes, it *sounds* cool, and I'm normally against introducing 
gratuitous constraints on functionality, but in this case I think I 
prefer restricting T to real number types.

Have in mind that not only will one have to disable (or introduce 
special cases for) abs() and arg(), but also some of the operations, in 
particular division and exponentiation.

It all sounds like more work, more maintenance, more complex code (hur 
hur), for very little or no benefit.

-Lars


Philippe Sigaud wrote:
> 
> 
> On Mon, Apr 19, 2010 at 23:05, Andrei Alexandrescu <andrei at erdani.com 
> <mailto:andrei at erdani.com>> wrote:
> 
>     It's a good point. Replying to your other point, we need some traits
>     to tell whether something is a built-in float. For those that look
>     like a float, we should define isFloatingPointLike.
> 
>     Andrei
> 
> 
>     On 04/19/2010 04:02 PM, Lars Tandle Kyllingstad wrote:
> 
>         Another point is that if Complex!T is to support arbitrary FP types,
>         then the trigonometric functions in std.math must too.
> 
> 
> Hi,
> 
> sorry to interrupt on your conversation (if I can post on the Phobos 
> list), but Lars' comment on CT interfaces got me thinking: is it enough 
> to test the subjacent type with these templates ?
> 
> - some type defines some operators (definesOperators!(T, "+", "-", ...)
> - some type can be used with some functions (acceptedBy!(T, "hypot", ...)
> - some type can be cast to real.
> 
> they could be all easily done, I think.   
> 
> Mostly, it seems to me your code would have a global constraint with 
> struct Complex(T) if (definesOperators!(T, /+ the whole paraphernalia+/)
> 
> And, just around abs and arg, testing if T is accepted by hypot and 
> atan2 _or_ if it can by explicitly cast to a real.
> 
> Commenting out abs/arg is enough to get  a Complex!BigInt to compile.
> but assignment does not work:
> 
> Complex!BigInt c;
> c = 23; // opAssign asks for a BigInt (R : T)
> maybe you should ask for something that can be cast to T.
> 
> Complex opAssign(R)(R r) if (__traits(compiles, {T t; R r; t=r;} ))
>     {
>         re = r;
>         im = 0;
>         return this;
>     }
> 
> Philippe
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


More information about the phobos mailing list