From 0e3c85ac25838551af3a3009a811f95ee05ab7d6 Mon Sep 17 00:00:00 2001 From: hinomori_minori Date: Sat, 7 Nov 2026 04:10:29 +0900 Subject: [PATCH] =?UTF-8?q?=E5=86=99=E4=BA=86=E5=B9=82=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E9=99=A4=E6=B3=95=E6=B2=A1=E6=83=B3=E5=A5=BD=E6=80=8E?= =?UTF-8?q?=E4=B9=88=E5=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pi.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pi.c b/pi.c index 016f6ab..2cbf73d 100644 --- a/pi.c +++ b/pi.c @@ -16,6 +16,8 @@ struct fn { struct bn denominator; }; +#define DECIMAL_PLACES 1024 + #define BN_ZERO (struct bn){NULL,0} bool bn_bigger(struct bn _bn,unsigned int _i){ @@ -221,6 +223,45 @@ struct bn bn_muti_bn(struct bn _bn1,struct bn _bn2,struct bn* output,unsigned lo } } +void bn_copy(struct bn* _des,struct bn _src){ + if(_des->_p==NULL){ + _des->_p = malloc(_src._i*sizeof(unsigned int)); + _des->_i=_src._i; + }else{ + unsigned int* _np = realloc(_des->_p,_src._i*sizeof(unsigned int)); + if(_np!=NULL){ + _des->_p=_np; + _des->_i=_src._i; + return; + } + } + memcpy(_des->_p,_src._p,_des->_i*sizeof(unsigned int)); + return; +} + +struct bn bn_power(struct bn* _bn,unsigned long index){ + if(index<0){ + return BN_ZERO; + } + if(index==0){ + struct bn res = nn2bn(1); + bn_copy(_bn,res); + free(res._p); + return nn2bn(1); + } + if(index==1){ + return *_bn; + } + struct bn res = BN_ZERO,copy = BN_ZERO; + bn_copy(&res,*_bn);bn_copy(©,*_bn); + for(int i=0;iUINT32_MAX){ unsigned int* _p=malloc(2*sizeof(int));