improve posint morphisms
This commit is contained in:
parent
6cfb25a1a7
commit
6f85e004b9
1 changed files with 15 additions and 10 deletions
|
@ -14,9 +14,9 @@ morph_nat_as_u64_to_pos ()
|
|||
return 0;
|
||||
```
|
||||
|
||||
morph_nat_as_u64_to_pos ()
|
||||
morph_nat_as_pos_to_u64 (Endianness:Type)
|
||||
ℕ
|
||||
~ <PosInt 0 LittleEndian>
|
||||
~ <PosInt 0 Endianness>
|
||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit 0>~x86.UInt64>
|
||||
--> ℕ
|
||||
~ x86.UInt64
|
||||
|
@ -42,14 +42,16 @@ morph_posint_radix_le (SrcRadix:ℤ, DstRadix:ℤ)
|
|||
|
||||
length_prefix_uint64_array_clear( dst );
|
||||
|
||||
if( DstRadix == 0 ) {
|
||||
#if DstRadix==0
|
||||
length_prefix_uint64_array_push( dst, value );
|
||||
} else if( DstRadix > 0 ) {
|
||||
while( value > 0 ) {
|
||||
#else
|
||||
if( value == 0 ) {
|
||||
length_prefix_uint64_array_push( dst, 0 );
|
||||
} else while( value > 0 ) {
|
||||
length_prefix_uint64_array_push( dst, value % DstRadix );
|
||||
value /= DstRadix;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
```
|
||||
|
@ -69,13 +71,16 @@ morph_posint_radix_be (SrcRadix:ℤ, DstRadix:ℤ)
|
|||
value += src->items[i];
|
||||
}
|
||||
|
||||
if( DstRadix == 0 ) {
|
||||
#if DstRadix==0
|
||||
dst->len = 1;
|
||||
dst->items[0] = value;
|
||||
} else {
|
||||
#else
|
||||
uint64_t v = value;
|
||||
dst->len = 0;
|
||||
while( v ) {
|
||||
|
||||
if( v == 0 ) {
|
||||
dst->len = 1;
|
||||
} else while( v ) {
|
||||
dst->len++;
|
||||
v /= DstRadix;
|
||||
}
|
||||
|
@ -85,7 +90,7 @@ morph_posint_radix_be (SrcRadix:ℤ, DstRadix:ℤ)
|
|||
dst->items[--i] = value % DstRadix;
|
||||
value /= DstRadix;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue