[phobos] Is anyone working on std.complex?
Lars Tandle Kyllingstad
lars at kyllingen.net
Fri Mar 26 01:41:36 PDT 2010
Don Clugston wrote:
> On 25 March 2010 22:54, Andrei Alexandrescu <andrei at erdani.com> wrote:
>> Good call! Walter mentioned he should transfer some knowledge to Don in the
>> matter. Walter, please let us know how we can plan this.
>>
>> Don suggested that the polar representation is very seldom used so we may as
>> well throw it away.
>
> That's not the direct reason. The issue is that it's difficult to do
> polar representation in a way which preserves numerically desirable
> properties. For instance, the invariant if (x==x) assert( x == -
> (-x)); MUST be preserved, but isn't true for a naive polar
> representation. This rules out the use of floating point for the arg
> -- you probably want to use some form of fixed point. Then you have
> the problem that PI isn't exactly representable as a floating-point
> number. And it's downhill from there.
Good points. When you think about it, most no-ops will end up being ops
for polar-form complex FP numbers if done naïvely.
-(-z)
z + 0
z.toCartesian.toPolar
> And this is the reason why polar representation is seldom used -- it's
> virtually always a bad idea.
> Generally speaking the best way of doing polar representation is to
> put a wrapper over a cartesian complex type!
I agree. I think having arg() and mod() as @properties of a Cartesian
complex type is good enough. They could even be setter properties, as
long as the documentation mentions the computational cost and numerical
error.
-Lars
>> On 03/25/2010 04:03 PM, Lars Tandle Kyllingstad wrote:
>>> Is anyone working, or planning to do work, on std.complex? If not, and
>>> if it is desirable, I could take a look at it. I guess the main thing
>>> that is needed is to add overloaded operators. Is there anything else?
>>>
>>> Also, I wonder: How do you feel about renaming "modulus" and "angle" to
>>> "mod" and "arg"? I seldom hear or use the term "angle" in relation to
>>> complex numbers. "Argument" and "phase" are much more common, and the
>>> standard mathematical notation for the argument of a complex number is
>>> Arg(z). Also, "mod" and "arg" are nice and short, like "re" and "im".
>>>
>>> -Lars
>>>
>>>
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
More information about the phobos
mailing list