Imaginary base numbers: Difference between revisions

Line 707:
 
=={{header|D}}==
{{incorrect|D|The outputs for the imaginary portions are suspect. The odd numbers are not round tripping correctly.}}
{{trans|Kotlin}}
<lang D>import std.algorithm;
Line 808 ⟶ 807:
foreach (j; posLen+1..b2i.length) {
auto k = (b2i[j] - '0').to!double;
if (k > 0.0) {
sum += prod * k;
}
prod *= invTwoI;
}
Line 845 ⟶ 847:
qi = c1.toQuaterImaginary();
c2 = cast(Complex!double) qi;
writefln("%4s -> %8s -> %4s ", c1.re, qi, c2.re);
}
writeln;
Line 852 ⟶ 854:
auto qi = c1.toQuaterImaginary;
auto c2 = qi.to!(Complex!double);
writef("%4s4si -> %8s -> %4s4si ", c1.im, qi, c2.im);
c1 = -c1;
qi = c1.toQuaterImaginary();
c2 = cast(Complex!double) qi;
writefln("%4s4si -> %8s -> %4s 4si", c1.im, qi, c2.im);
}
}</lang>
Line 877 ⟶ 879:
16 -> 10000 -> 16 -16 -> 1030000 -> -16
 
11i -> 10.2 -> 2 1i -11i -> 0.2 -> 0-1i
22i -> 10.0 -> 2 2i -22i -> 1030.0 -> -22i
33i -> 20.2 -> 4 3i -33i -> 1030.2 -> -23i
44i -> 20.0 -> 4 4i -44i -> 1020.0 -> -44i
55i -> 30.2 -> 6 5i -55i -> 1020.2 -> -45i
66i -> 30.0 -> 6 6i -66i -> 1010.0 -> -66i
77i -> 103000.2 -> 8 7i -77i -> 1010.2 -> -67i
88i -> 103000.0 -> 8 8i -88i -> 1000.0 -> -88i
99i -> 103010.2 -> 10 9i -99i -> 1000.2 -> -89i
10 10i -> 103010.0 -> 10 10i -1010i -> 2030.0 -> -1010i
11 11i -> 103020.2 -> 12 11i -1111i -> 2030.2 -> -1011i
12 12i -> 103020.0 -> 12 12i -1212i -> 2020.0 -> -1212i
13 13i -> 103030.2 -> 14 13i -1313i -> 2020.2 -> -1213i
14 14i -> 103030.0 -> 14 14i -1414i -> 2010.0 -> -1414i
15 15i -> 102000.2 -> 16 15i -1515i -> 2010.2 -> -1415i
16 16i -> 102000.0 -> 16 16i -1616i -> 2000.0 -> -1616i</pre>
 
=={{header|Go}}==
1,452

edits