Euler's identity: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Can now use Wren-complex for this task.) |
|||
Line 885: | Line 885: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-complex}} |
|||
As complex numbers are not built in, we create a bare-bones Complex class with only the methods we need to complete this task. |
|||
⚫ | |||
static exp(x) { |
|||
var e = 2.718281828459045 |
|||
return e.pow(x) |
|||
} |
|||
} |
|||
⚫ | |||
class Complex { |
|||
construct new(real, imag) { |
|||
_real = real |
|||
_imag = imag |
|||
} |
|||
real { _real } |
|||
imag { _imag } |
|||
+ (other) { Complex.new(_real + other.real, _imag + other.imag) } |
|||
exp { |
|||
var re = Num2.exp(_real) |
|||
return Complex.new(re * _imag.cos, re * _imag.sin) |
|||
} |
|||
toString { (_imag >= 0) ? "%(_real) + %(_imag)i" : "%(_real) - %(-_imag)i" } |
|||
static one { Complex.new(1, 0) } |
|||
} |
|||
System.print((Complex.new(0, Num.pi).exp + Complex.one).toString)</lang> |
System.print((Complex.new(0, Num.pi).exp + Complex.one).toString)</lang> |