-
Notifications
You must be signed in to change notification settings - Fork 206
added integer log with positive integer base #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
670636f
added integer log with positive integer base
czurnieden ecd6a02
additional corrections for MP_8BIT
czurnieden 4d2312f
added prime-sieve (segmented) and documentation
czurnieden 9207a58
replaced function macros with actual functions
czurnieden da2c192
addition of mp_expt; fixed mp_n_root_ex in general and for MP_8BIT; a…
czurnieden c6cfcae
fixed memory leak
czurnieden d078d7c
put tests back in order
czurnieden 7ef98d3
added factoring
czurnieden 57d20b8
added testing for the extra functions to Travis
czurnieden 2aa2cf6
added deterministic primality test
czurnieden ff88ce9
reinstalled all tests
czurnieden f4df64e
additional castings to test.c
czurnieden 5b82a22
resolved memory problem
czurnieden 64f3528
removed extraneous delimiter
czurnieden 1020f43
bugfixes and cleanups
czurnieden da630d8
bugfixes and cleanup (API change in the sieve-functions!)
czurnieden 1758eaf
caught a rogue #endif and put it back in its place
czurnieden 39f8693
added necessary macro
czurnieden f3a464d
documentation update
czurnieden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "tommath_private.h" | ||
#ifdef BN_MP_DECR_C | ||
/* LibTomMath, multiple-precision integer library -- Tom St Denis | ||
* | ||
* LibTomMath is a library that provides multiple-precision | ||
* integer arithmetic as well as number theoretic functionality. | ||
* | ||
* The library was designed directly after the MPI library by | ||
* Michael Fromberger but has been written from scratch with | ||
* additional optimizations in place. | ||
* | ||
* SPDX-License-Identifier: Unlicense | ||
*/ | ||
|
||
/* Decrement "a" by one like "a--". Changes input! */ | ||
#ifdef LTM_USE_EXTRA_FUNCTIONS | ||
int mp_decr(mp_int *a) | ||
{ | ||
int e; | ||
if (IS_ZERO(a)) { | ||
mp_set(a,1uL); | ||
a->sign = MP_NEG; | ||
return MP_OKAY; | ||
} else if (a->sign == MP_NEG) { | ||
a->sign = MP_ZPOS; | ||
if ((e = mp_incr(a)) != MP_OKAY) { | ||
a->sign = MP_NEG; | ||
return e; | ||
} | ||
a->sign = MP_NEG; | ||
return MP_OKAY; | ||
} else if ((a->used == 1) && (a->dp[0] > 1uL)) { | ||
a->dp[0]--; | ||
if (a->dp[0] == 0) { | ||
mp_zero(a); | ||
} | ||
return MP_OKAY; | ||
} else { | ||
return mp_sub_d(a, 1uL,a); | ||
} | ||
} | ||
#endif | ||
#endif | ||
/* ref: \$Format:\%D$ */ | ||
/* git commit: \$Format:\%H$ */ | ||
/* commit time: \$Format:\%ai$ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "tommath_private.h" | ||
#ifdef BN_MP_EXPT_C | ||
/* LibTomMath, multiple-precision integer library -- Tom St Denis | ||
* | ||
* LibTomMath is a library that provides multiple-precision | ||
* integer arithmetic as well as number theoretic functionality. | ||
* | ||
* The library was designed directly after the MPI library by | ||
* Michael Fromberger but has been written from scratch with | ||
* additional optimizations in place. | ||
* | ||
* SPDX-License-Identifier: Unlicense | ||
*/ | ||
|
||
/* exponentiate a^b = c with a, b, c big integers */ | ||
int mp_expt(const mp_int *a, const mp_int *b, mp_int *c) | ||
{ | ||
mp_int tmp,e; | ||
int err; | ||
|
||
/* only positive exponents for now */ | ||
if (b->sign == MP_NEG) { | ||
return MP_VAL; | ||
} | ||
|
||
if ((err = mp_init_multi(&tmp,&e,NULL)) != MP_OKAY) { | ||
return err; | ||
} | ||
if ((err = mp_copy(a,&tmp)) != MP_OKAY) { | ||
return err; | ||
} | ||
if ((err = mp_copy(b,&e)) != MP_OKAY) { | ||
return err; | ||
} | ||
if ((err = mp_set_int(c,1)) != MP_OKAY) { | ||
return err; | ||
} | ||
while (!IS_ZERO(&e)) { | ||
if (mp_isodd(&e)) { | ||
if ((err = mp_mul(c,&tmp,c)) != MP_OKAY) { | ||
return err; | ||
} | ||
} | ||
if ((err = mp_div_2(&e, &e)) != MP_OKAY) { | ||
return err; | ||
} | ||
if (!IS_ZERO(&e)) { | ||
if ((err = mp_sqr(&tmp,&tmp)) != MP_OKAY) { | ||
return err; | ||
} | ||
} | ||
} | ||
if (a->sign == MP_NEG) { | ||
c->sign = (mp_isodd(b))?MP_NEG:MP_ZPOS; | ||
} | ||
mp_clear_multi(&tmp,&e,NULL); | ||
return MP_OKAY; | ||
} | ||
|
||
#endif | ||
/* ref: \$Format:\%D$ */ | ||
/* git commit: \$Format:\%H$ */ | ||
/* commit time: \$Format:\%ai$ */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this macro can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It changes the input, not a very common thing in LibTomMath, so I was a bit cautious here.
But if that (remove the macro for this function and this function only) is not what you meant drop me a note please.