C#, 25 bytes, type: double
Bare form of a lambda expression:
x=>System.Math.Pow(x,1/x)
The expression can be assigned to a function variable, e.g. (Func<double, double>
), ...
System.
can be omitted, if using System;
is used (but more bytes).
Complete test program (143 bytes) with the input of the question:
using System;class P{static void Main(){Array.ForEach(new double[]{-.2,-.5,.5,1,2,Math.E,3,100,10000},x=>Console.WriteLine(Math.Pow(x,1/x)));}}
Result:
-3125
4
0,25
1
1,4142135623731
1,44466786100977
1,44224957030741
1,0471285480509
1,0009214583193
C#, 37 bytes, type: Complex
x=>System.Numerics.Complex.Pow(x,1/x)
Also the assembly for System.Numerics
needs to be referenced.
The division operator is overloaded for complex arguments.
Test program (189 bytes) with the input of the question for complex numbers:
using System;using C=System.Numerics.Complex;class P{static void Main(){Array.ForEach(new C[]{new C(-2,0),new C(0,1),new C(0,2),new C(1,2),new C(2,2)},x=>Console.WriteLine(C.Pow(x,1/x)));}}
Result:
(4,32963728535968E-17, -0,707106781186548)
(4,81047738096535, 0)
(2,0628722350809, -0,745007062179724)
(1,81984053615444, -0,183434723804562)
(1,57500291115344, -0,100274868564155)
Test program (264 bytes) with infinity:
using System;using C=System.Numerics.Complex;class P{static void Main(){var p=double.PositiveInfinity;var n=double.NegativeInfinity;Array.ForEach(new C[]{new C(-1/p,0),new C(0,0),new C(1/p,0),new C(p,0),new C(n,0),new C(n,2) },x=>Console.WriteLine(C.Pow(x,1/x)));}}
Result:
(0, 0)
(0, 0)
(0, 0)
(1, 0)
(1, 0)
(1, 0)