Skip to content

Commit

Permalink
Add Sqrt
Browse files Browse the repository at this point in the history
  • Loading branch information
JPZEBRA committed May 23, 2021
1 parent 0670db9 commit 2b2eefe
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/FloatedBigDigit32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3106,6 +3106,36 @@ int FloatedBigDigit32::PowerDiv_boost(FloatedBigDigit32* V) {

}

/****************************************************************************/

int FloatedBigDigit32::Sqrt() {

if(this->isOver()) {
this->overflow();
return floatedBigDigitERR;
}

if(this->isZero()) {
this->clear();
return floatedBigDigitOK;
}

if(this->isMinus()) {
this->overflow();
return floatedBigDigitERR;
}

FloatedBigDigit32* F = new FloatedBigDigit32();

F->set(2);

int ret = this->PowerDiv(F);

delete F;

return ret;

}

/****************************************************************************/
/****************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions lib/FloatedBigDigit32.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ class FloatedBigDigit32 {

int PowerDiv(FloatedBigDigit32* V);

int Sqrt();

/****************************************************************************/

int SetSin(FloatedBigDigit32* V);
Expand Down
37 changes: 37 additions & 0 deletions test/sqrt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "FloatedBigDigit32.h"

int main(int argc,const char **argv) {

char buff[10000];

if(argc!=3) {
printf("USAGE: sqrt KETA value \n");
return 0;
}

long KETA = atol(argv[1]);

SetFloatedBigDigit32Keta((int)KETA);

FloatedBigDigit32* VAL = new FloatedBigDigit32();

VAL->Set(argv[2]);

int ret = VAL->Sqrt();

VAL->toString(buff,10000,false);

printf("%s R:%d\n",buff,ret);

delete VAL;

FreeFloatedBigDigit32();

return 0;

}

0 comments on commit 2b2eefe

Please sign in to comment.