Libraryless. Click here for Pure Java version (3903L/22K).
1 | srecord Complex(double re, double im) { |
2 | double abs() { ret sqrt(re*re+im*im); } |
3 | |
4 | double re() { ret re; } |
5 | double im() { ret im; } |
6 | |
7 | double phase aka angle() { ret Math.atan2(im, re); } |
8 | double fracAngle() { ret fracNonNeg(angle()/twoPi()); } // angle as 0 to 1 |
9 | |
10 | toString { |
11 | if (im != 0) |
12 | ret re == 0 ? im + "i" : re + plusPrefixUnlessMinus(str(im)) + "i"; |
13 | else |
14 | ret str(re); |
15 | } |
16 | } |
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj, podlckwnjdmb, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1032421 |
Snippet name: | Complex - complex number (double precision) |
Eternal ID of this version: | #1032421/9 |
Text MD5: | 3bcbc50bbbdf01ab0141ad750c5eb901 |
Transpilation MD5: | 79209f398970f622aee026078ec23a06 |
Author: | stefan |
Category: | javax / maths |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-18 10:24:53 |
Source code size: | 427 bytes / 16 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 289 / 1785 |
Version history: | 8 change(s) |
Referenced in: | [show references] |