Imaginary base numbers: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
(J) |
||
Line 1,610: | Line 1,610: | ||
"3z.8" |
"3z.8" |
||
0.0 :+ 7.75</pre> |
0.0 :+ 7.75</pre> |
||
=={{header|J}}== |
|||
Implementation: |
|||
<lang J> |
|||
ibdec=: {{ |
|||
0j2 ibdec y |
|||
: |
|||
digits=. 0,".,~&'36b'@> tolower y -.'. ' |
|||
(x #. digits) % x^#(}.~ 1+i.&'.')y-.' ' |
|||
}}"1 |
|||
ibenc=: {{ |
|||
0j2 ibenc y |
|||
: |
|||
if.0=y do.,'0' return.end. |
|||
sq=:*:x |
|||
step=: }.,~(1,|sq) +^:(0>{:@]) (0,sq) #: {. |
|||
seq=: step^:(0~:{.)^:_ |
|||
raw=: ,hfd(}.~0 i.~0=]),|:seq"0 (1,|x)*+.y |
|||
trimfrac=. (#!.'.'~ 1 j. 2|.#{.1:)`}:@.((1<#)*'0'={:) |
|||
trimfrac raw |
|||
}}"0 </lang> |
|||
This ibdec can handle decoded numbers in complex bases up to 0j6, but this ibenc can only represent digits in complex bases up to 0j4. |
|||
Examples: |
|||
<lang J> |
|||
(ibenc i:16),.' ',.ibenc j.i:16 |
|||
1030000 102000 |
|||
1030001 102000.2 |
|||
1030002 103030 |
|||
1030003 103030.2 |
|||
300 103020 |
|||
301 103020.2 |
|||
302 103010 |
|||
303 103010.2 |
|||
200 103000 |
|||
201 103000.2 |
|||
202 30 |
|||
203 30.2 |
|||
100 20 |
|||
101 20.2 |
|||
102 10 |
|||
103 10.2 |
|||
0 0 |
|||
1 2. |
|||
2 1030 |
|||
3 1030.2 |
|||
10300 1020 |
|||
10301 1020.2 |
|||
10302 1010 |
|||
10303 1010.2 |
|||
10200 1000 |
|||
10201 1000.2 |
|||
10202 2030 |
|||
10203 2030.2 |
|||
10100 2020 |
|||
10101 2020.2 |
|||
10102 2010 |
|||
10103 2010.2 |
|||
10000 2000 |
|||
(ibdec ibenc i:16),: ibdec ibenc j.i:16 |
|||
_16 _15 _14 _13 _12 _11 _10 _9 _8 _7 _6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|||
0j16 0j15 0j14 0j13 0j12 0j11 0j10 0j9 0j8 0j7 0j6 0j5 0j4 0j3 0j2 0j1 0 2 0j_2 0j_3 0j_4 0j_5 0j_6 0j_7 0j_8 0j_9 0j_10 0j_11 0j_12 0j_13 0j_14 0j_15 0j_16 |
|||
0j4 ibenc 42 |
|||
10e0a |
|||
0j4 ibdec 0j4 ibenc 42 |
|||
42 |
|||
</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |