ldmc/morphisms/posint.morphism-base

77 lines
1.9 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

morph_posint_radix_le (SrcRadix:, DstRadix:)
~ <PosInt SrcRadix LittleEndian>
~ <Seq~<LengthPrefix x86.UInt64> <Digit SrcRadix>~x86.UInt64>
-->
~ <PosInt DstRadix LittleEndian>
~ <Seq~<LenghtPrefix x86.UInt64> <Digit DstRadix>~x86.UInt64>
```
uint64_t value = 0;
for( uint64_t i = 0; i < src->len; ++i ) {
value *= SrcRadix;
value += src->items[src->len - i - 1];
}
length_prefix_uint64_array_clear( dst );
while( value > 0 ) {
length_prefix_uint64_array_push( dst, value % DstRadix );
value /= DstRadix;
}
return 0;
```
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>
```
uint64_t value = 0;
for( uint64_t i = 0; i < src->len; ++i ) {
value *= SrcRadix;
value += src->items[i];
}
uint64_t v = value;
dst->len = 0;
while( v ) {
dst->len++;
v /= DstRadix;
}
uint64_t i = dst->len;
while( value > 0 ) {
dst->items[--i] = ( dst, value % DstRadix );
value /= DstRadix;
}
return 0;
```
morph_posint_endianness (Radix:)
~ <PosInt Radix LittleEndian>
~ <Seq~<LengthPrefix x86.UInt64> <Digit Radix> ~ x86.UInt64>
-->
~ <PosInt Radix BigEndian>
~ <Seq~<LengthPrefix x86.UInt64> <Digit Radix> ~ x86.UInt64>
```
return length_prefix_uint64_array_reverse( src, dst );
```
morph_posint_endianness (Radix:)
~ <PosInt Radix BigEndian>
~ <Seq~<LengthPrefix x86.UInt64> <Digit Radix> ~ x86.UInt64>
-->
~ <PosInt Radix LittleEndian>
~ <Seq~<LengthPrefix x86.UInt64> <Digit Radix> ~ x86.UInt64>
```
return length_prefix_uint64_array_reverse( src, dst );
```