Imaginary base numbers: Difference between revisions

Content added Content deleted
m (J: bugfix)
Line 1,627: Line 1,627:
:
:
if.0=y do.,'0' return.end.
if.0=y do.,'0' return.end.
sq=:*:x
sq=.*:x assert. 17 > sq
step=: }.,~(1,|sq) +^:(0>{:@]) (0,sq) #: {.
step=. }.,~(1,|sq) +^:(0>{:@]) (0,sq) #: {.
seq=: step^:(0~:{.)^:_
seq=. step^:(0~:{.)^:_"0
're im0'=.+.y
raw=: ,hfd(}.~0 i.~0=]),|:seq"0 (1,|x)*+.y
'im imf'=.(sign,1)*(0,|x)#:im0*sign=.*im0
trimfrac=. (#!.'.'~ 1 j. 2|.#{.1:)`}:@.((1<#)*'0'={:)
frac=. ,hfd (imf*|x)-.0 if.#frac do.frac=.'.',frac end.
trimfrac raw
frac,~(}.~0 i.~_1}.'0'=]) }:,hfd|:0 1|."0 1 seq re,im
}}"0 </lang>
}}"0
</lang>


This ibdec can decode numbers from complex bases up to 0j6, but this ibenc can only represent digits in complex bases up to 0j4.
This ibdec can decode numbers from complex bases up to 0j6, but this ibenc can only represent digits in complex bases up to 0j4.
Line 1,641: Line 1,643:
<lang J>
<lang J>
(ibenc i:16),.' ',.ibenc j.i:16
(ibenc i:16),.' ',.ibenc j.i:16
1030000 102000
1030000 2000
1030001 102000.2
1030001 2010.2
1030002 103030
1030002 2010
1030003 103030.2
1030003 2020.2
300 103020
300 2020
301 103020.2
301 2030.2
302 103010
302 2030
303 103010.2
303 1000.2
200 103000
200 1000
201 103000.2
201 1010.2
202 30
202 1010
203 30.2
203 1020.2
100 20
100 1020
101 20.2
101 1030.2
102 10
102 1030
103 10.2
103 0.2
0 0
0 0
1 2.
1 0.2
2 1030
2 10
3 1030.2
3 10.2
10300 1020
10300 20
10301 1020.2
10301 20.2
10302 1010
10302 30
10303 1010.2
10303 30.2
10200 1000
10200 103000
10201 1000.2
10201 103000.2
10202 2030
10202 103010
10203 2030.2
10203 103010.2
10100 2020
10100 103020
10101 2020.2
10101 103020.2
10102 2010
10102 103030
10103 2010.2
10103 103030.2
10000 2000
10000 102000
(ibdec ibenc i:16),: ibdec ibenc j.i:16
(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
_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
0j_16 0j_15 0j_14 0j_13 0j_12 0j_11 0j_10 0j_9 0j_8 0j_7 0j_6 0j_5 0j_4 0j_3 0j_2 0j_1 0 0j_1 0j2 0j1 0j4 0j3 0j6 0j5 0j8 0j7 0j10 0j9 0j12 0j11 0j14 0j13 0j16
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
0j4 ibenc 42
10e0a
10e0a