1 2 3 4 5 6 7 8 9 10 |
u4 bigint_shrink_i(bigint *dest) { u4 dlen=dest->len; for (u4 i=dest->len;i>0;i--) { if (dest->dats[i-1]==0)dest->len--; else break ; } return dlen; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
void bigint_print( FILE *file, const bigint *src) { bigint temp; u4 srcsize=bigint_size_i(src); if (srcsize==0) { fprintf (file, "0" ); return ; } u4 dcsizemax=10704*srcsize/10000+1; bigint_create(dcsizemax, &temp); bigint_setu4(&temp, 0); temp.len=0; for (u4 i=srcsize-1;( long )i>=0;i--) { for (u4 bit=31;( long )bit>=0;bit--) { for (u4 j=0;j<temp.len;j++) { if (temp.dats[j]>=500000000)temp.dats[j]+=1647483648; } if (temp.len<dcsizemax)temp.len++; bigint_shlu4(&temp, 1); if (src->dats[i] & (1<<bit))temp.dats[0]|=1; bigint_shrink_i(&temp); } } u4 dcsize=bigint_size_i(&temp); fprintf (file, "%u" , (unsigned int )temp.dats[dcsize-1]); for (u4 i=dcsize-2;( long )i>=0;i--) { fprintf (file, "%09u" , (unsigned int )temp.dats[i]); } bigint_release(&temp); } |
BigFloat로 Pi를 구해보자-0. 시작하며 (1) | 2012.10.16 |
---|---|
드디어 오류를 잡아냈다. (2) | 2010.09.11 |
BigInteger를 구현해보자 - 10. 10진수로 입력받기 (5) | 2009.04.30 |
BigInteger를 구현해보자 - 8. 10진수로 출력하기(알고리즘) (3) | 2009.04.26 |
BigInteger를 구현해보자 - 7. 나누기 (2) | 2009.04.25 |
BigInteger를 구현해보자 - 6. 크기비교 (4) | 2009.04.21 |
댓글 영역