Arithmetic/Complex: Difference between revisions
Content deleted Content added
No edit summary |
added Nemerle |
||
Line 1,800: | Line 1,800: | ||
1 / z1 = 0.15 - 0.09 i |
1 / z1 = 0.15 - 0.09 i |
||
- z1 = -5.00 - 3.00 i</pre> |
- z1 = -5.00 - 3.00 i</pre> |
||
=={{header|Nemerle}}== |
|||
<lang Nemerle>using System; |
|||
using System.Console; |
|||
using System.Numerics; |
|||
using System.Numerics.Complex; |
|||
module RCComplex |
|||
{ |
|||
PrettyPrint(this c : Complex) : string |
|||
{ |
|||
mutable sign = '+'; |
|||
when (c.Imaginary < 0) sign = '-'; |
|||
$"$(c.Real) $sign $(Math.Abs(c.Imaginary))i" |
|||
} |
|||
Main() : void |
|||
{ |
|||
def complex1 = Complex(1.0, 1.0); |
|||
def complex2 = Complex(3.14159, 1.2); |
|||
WriteLine(Add(complex1, complex2).PrettyPrint()); |
|||
WriteLine(Multiply(complex1, complex2).PrettyPrint()); |
|||
WriteLine(Negate(complex2).PrettyPrint()); |
|||
WriteLine(Reciprocal(complex2).PrettyPrint()); |
|||
WriteLine(Conjugate(complex2).PrettyPrint()); |
|||
} |
|||
}</lang> |
|||
Output: |
|||
<pre>4.14159 + 2.2i |
|||
1.94159 + 4.34159i |
|||
-3.14159 - 1.2i |
|||
0.277781124787984 - 0.106104663481097i |
|||
3.14159 - 1.2i</pre> |
|||
=={{header|Oberon-2}}== |
=={{header|Oberon-2}}== |