If you're going to have versions of sqrt in S29 that deal with Complex
numbers, you ought to do likewise with a number of other functions:

multi sub abs (: Complex ?$x = $CALLER::_ ) returns Num
  should return the magnitude of a complex number.  abs($x) :=
$x.magnitude, or whatever the appropriate method for extracting the
magnitude of a Complex number is.  (I'm unaware of the exact
terminology used within Complex, or even if it has been established

multi sub sign (: Complex ?$x = $CALLER::_) returns Complex
  Since I would expect $x == sign($x) * abs($x) to be true for Nums,
the sign of a complex number would logically be a unitary complex
number, or zero if $x is zero: sign($x) := ($x == 0) ?? 0 :: $x /
abs($x).  Thus, this would be distinct from $x.angle, or whatever it's
called, which would return a Num representing the direction as
measured in radians, degrees, etc.

multi sub exp (: Complex ?$exponent = $CALLER::_, Complex +$base)
returns Complex
multi sub log (: Complex ?$exponent = $CALLER::_, Complex +$base)
returns Complex
multi sub func (: Complex ?$x = $CALLER::_, +$base) returns Complex
(where func is any trig-related function)
  IIRC, raising  a base to a Complex exponent raises the base's
absolute value by the real component of the exponent, and rotates its
angle (as measured in radians) by the imaginary component.
  All of the trig functions can be aliased to expressions using exp
and log.  This may be useful for the purpose of defining the Complex
  All of these functions, as well as sqrt, need to restrict the range
of valid return values: frex, sqrt ought to always return something
with either a positive real component or a zero real component and a
non-negative imaginary component.
  (Another possibility would be to return a list of every possible
result when in list context, with the result that you'd get in scalar
context being element zero of the list.  This even has its uses wrt
sqrt(Num), providing a two-element list of the positive and negative
roots, in that order.  This option would apply to sqrt, exp, log, and
the trig functions.)
  This has implications for the infix:<**> operator as well.

Jonathan "Dataweaver" Lang

Reply via email to