add radix morphism for little and big endian
This commit is contained in:
parent
638bb690aa
commit
c270efbb87
3 changed files with 64 additions and 7 deletions
morphisms
|
@ -27,7 +27,13 @@ int morph_posint_endianness(
|
||||||
struct LengthPrefixUInt64Array const * restrict src,
|
struct LengthPrefixUInt64Array const * restrict src,
|
||||||
struct LengthPrefixUInt64Array * restrict dst
|
struct LengthPrefixUInt64Array * restrict dst
|
||||||
);
|
);
|
||||||
int morph_posint_radix(
|
int morph_posint_radix_le(
|
||||||
|
uint64_t const src_radix,
|
||||||
|
uint64_t const dst_radix,
|
||||||
|
struct LengthPrefixUInt64Array const * restrict src,
|
||||||
|
struct LengthPrefixUInt64Array * restrict dst
|
||||||
|
);
|
||||||
|
int morph_posint_radix_be(
|
||||||
uint64_t const src_radix,
|
uint64_t const src_radix,
|
||||||
uint64_t const dst_radix,
|
uint64_t const dst_radix,
|
||||||
struct LengthPrefixUInt64Array const * restrict src,
|
struct LengthPrefixUInt64Array const * restrict src,
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
morph_digit_as_char_to_uint8 (Radix:ℤ_16)
|
morph_digit_as_char_to_uint8 (Radix:ℤ_16)
|
||||||
<Digit Radix> ~ Char ~ Ascii ~ Byte
|
<Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
||||||
--> <Digit Radix> ~ x86.UInt8 ~ Byte
|
--> <Digit Radix> ~ x86.UInt8
|
||||||
@lib/libmorph-posint.so:src/posint.c
|
@lib/libmorph-posint.so:src/posint.c
|
||||||
|
|
||||||
morph_digit_as_uint8_to_char (Radix:ℤ_16)
|
morph_digit_as_uint8_to_char (Radix:ℤ_16)
|
||||||
<Digit Radix> ~ x86.UInt8 ~ Byte
|
<Digit Radix> ~ x86.UInt8
|
||||||
--> <Digit Radix> ~ Char ~ Ascii ~ Byte
|
--> <Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
||||||
@lib/libmorph-posint.so:src/posint.c
|
@lib/libmorph-posint.so:src/posint.c
|
||||||
|
|
||||||
morph_posint_radix (SrcRadix:ℤ, DstRadix:ℤ)
|
morph_digit_as_char_to_uint64 (Radix:ℤ_16)
|
||||||
|
<Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
||||||
|
--> <Digit Radix> ~ x86.UInt64
|
||||||
|
@lib/libmorph-posint.so:src/posint.c
|
||||||
|
|
||||||
|
morph_digit_as_uint64_to_char (Radix:ℤ_16)
|
||||||
|
<Digit Radix> ~ x86.UInt64
|
||||||
|
--> <Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
||||||
|
@lib/libmorph-posint.so:src/posint.c
|
||||||
|
|
||||||
|
morph_posint_radix_le (SrcRadix:ℤ, DstRadix:ℤ)
|
||||||
ℕ
|
ℕ
|
||||||
~ <PosInt SrcRadix LittleEndian>
|
~ <PosInt SrcRadix LittleEndian>
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit SrcRadix>~x86.UInt64>
|
~ <Seq~<LengthPrefix x86.UInt64> <Digit SrcRadix>~x86.UInt64>
|
||||||
|
@ -17,6 +27,15 @@ morph_posint_radix (SrcRadix:ℤ, DstRadix:ℤ)
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit DstRadix>~x86.UInt64>
|
~ <Seq~<LengthPrefix x86.UInt64> <Digit DstRadix>~x86.UInt64>
|
||||||
@lib/libmorph-posint.so:src/posint.c
|
@lib/libmorph-posint.so:src/posint.c
|
||||||
|
|
||||||
|
morph_posint_radix_be (SrcRadix:ℤ, DstRadix:ℤ)
|
||||||
|
ℕ
|
||||||
|
~ <PosInt SrcRadix BigEndian>
|
||||||
|
~ <Seq~<LengthPrefix x86.UInt64> <Digit SrcRadix>~x86.UInt64>
|
||||||
|
--> ℕ
|
||||||
|
~ <PosInt DstRadix BigEndian>
|
||||||
|
~ <Seq~<LengthPrefix x86.UInt64> <Digit DstRadix>~x86.UInt64>
|
||||||
|
@lib/libmorph-posint.so:src/posint.c
|
||||||
|
|
||||||
morph_posint_endianness (Radix:ℤ)
|
morph_posint_endianness (Radix:ℤ)
|
||||||
ℕ
|
ℕ
|
||||||
~ <PosInt Radix LittleEndian>
|
~ <PosInt Radix LittleEndian>
|
||||||
|
|
|
@ -62,7 +62,7 @@ int morph_posint_endianness(
|
||||||
|
|
||||||
/* morph radix in little endian
|
/* morph radix in little endian
|
||||||
*/
|
*/
|
||||||
int morph_posint_radix(
|
int morph_posint_radix_le(
|
||||||
uint64_t const src_radix,
|
uint64_t const src_radix,
|
||||||
uint64_t const dst_radix,
|
uint64_t const dst_radix,
|
||||||
|
|
||||||
|
@ -85,3 +85,35 @@ int morph_posint_radix(
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* morph radix in little endian
|
||||||
|
*/
|
||||||
|
int morph_posint_radix_be(
|
||||||
|
uint64_t const src_radix,
|
||||||
|
uint64_t const dst_radix,
|
||||||
|
|
||||||
|
struct LengthPrefixUInt64Array const * restrict src,
|
||||||
|
struct LengthPrefixUInt64Array * restrict dst
|
||||||
|
) {
|
||||||
|
uint64_t value = 0;
|
||||||
|
|
||||||
|
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||||
|
value *= src_radix;
|
||||||
|
value += src->items[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t v = value;
|
||||||
|
dst->len = 0;
|
||||||
|
while( v ) {
|
||||||
|
dst->len++;
|
||||||
|
v /= dst_radix;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t i = dst->len;
|
||||||
|
while( value > 0 ) {
|
||||||
|
dst->items[--i] = ( dst, value % dst_radix );
|
||||||
|
value /= dst_radix;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue