Merge pull request #134 from libtom/fixup/123_124
Fixup PR for #123 #124
This commit is contained in:
commit
7b9082554f
@ -49,9 +49,14 @@ int mp_set_double(mp_int *a, double b)
|
|||||||
return MP_OKAY;
|
return MP_OKAY;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
/* pragma message() not supported by several compilers (in mostly older but still used versions) */
|
||||||
|
# ifdef _MSC_VER
|
||||||
|
# pragma message("mp_set_double implementation is only available on platforms with IEEE754 floating point format")
|
||||||
|
# else
|
||||||
# warning "mp_set_double implementation is only available on platforms with IEEE754 floating point format"
|
# warning "mp_set_double implementation is only available on platforms with IEEE754 floating point format"
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ref: $Format:%D$ */
|
/* ref: $Format:%D$ */
|
||||||
/* git commit: $Format:%H$ */
|
/* git commit: $Format:%H$ */
|
||||||
|
48
demo/demo.c
48
demo/demo.c
@ -284,20 +284,20 @@ int main(void)
|
|||||||
/* test mp_tc_div_2d */
|
/* test mp_tc_div_2d */
|
||||||
printf("\n\nTesting: mp_tc_div_2d");
|
printf("\n\nTesting: mp_tc_div_2d");
|
||||||
for (i = 0; i < 1000; ++i) {
|
for (i = 0; i < 1000; ++i) {
|
||||||
int l, m;
|
int l, em;
|
||||||
|
|
||||||
l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
||||||
mp_set_int(&a, labs(l));
|
mp_set_int(&a, labs(l));
|
||||||
if (l < 0)
|
if (l < 0)
|
||||||
mp_neg(&a, &a);
|
mp_neg(&a, &a);
|
||||||
|
|
||||||
m = rand() % 32;
|
em = rand() % 32;
|
||||||
|
|
||||||
mp_set_int(&d, labs(l >> m));
|
mp_set_int(&d, labs(l >> em));
|
||||||
if ((l >> m) < 0)
|
if ((l >> em) < 0)
|
||||||
mp_neg(&d, &d);
|
mp_neg(&d, &d);
|
||||||
|
|
||||||
mp_tc_div_2d(&a, m, &b);
|
mp_tc_div_2d(&a, em, &b);
|
||||||
if (mp_cmp(&b, &d) != MP_EQ) {
|
if (mp_cmp(&b, &d) != MP_EQ) {
|
||||||
printf("\nmp_tc_div_2d() bad result!");
|
printf("\nmp_tc_div_2d() bad result!");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -305,22 +305,22 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* test mp_tc_xor */
|
/* test mp_tc_xor */
|
||||||
printf("\n\nTesting: mp_tc_or");
|
printf("\n\nTesting: mp_tc_xor");
|
||||||
for (i = 0; i < 1000; ++i) {
|
for (i = 0; i < 1000; ++i) {
|
||||||
int l, m;
|
int l, em;
|
||||||
|
|
||||||
l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
||||||
mp_set_int(&a, labs(l));
|
mp_set_int(&a, labs(l));
|
||||||
if (l < 0)
|
if (l < 0)
|
||||||
mp_neg(&a, &a);
|
mp_neg(&a, &a);
|
||||||
|
|
||||||
m = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
em = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
||||||
mp_set_int(&b, labs(m));
|
mp_set_int(&b, labs(em));
|
||||||
if (m < 0)
|
if (em < 0)
|
||||||
mp_neg(&b, &b);
|
mp_neg(&b, &b);
|
||||||
|
|
||||||
mp_set_int(&d, labs(l ^ m));
|
mp_set_int(&d, labs(l ^ em));
|
||||||
if ((l ^ m) < 0)
|
if ((l ^ em) < 0)
|
||||||
mp_neg(&d, &d);
|
mp_neg(&d, &d);
|
||||||
|
|
||||||
mp_tc_xor(&a, &b, &c);
|
mp_tc_xor(&a, &b, &c);
|
||||||
@ -333,20 +333,20 @@ int main(void)
|
|||||||
/* test mp_tc_or */
|
/* test mp_tc_or */
|
||||||
printf("\n\nTesting: mp_tc_or");
|
printf("\n\nTesting: mp_tc_or");
|
||||||
for (i = 0; i < 1000; ++i) {
|
for (i = 0; i < 1000; ++i) {
|
||||||
int l, m;
|
int l, em;
|
||||||
|
|
||||||
l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
||||||
mp_set_int(&a, labs(l));
|
mp_set_int(&a, labs(l));
|
||||||
if (l < 0)
|
if (l < 0)
|
||||||
mp_neg(&a, &a);
|
mp_neg(&a, &a);
|
||||||
|
|
||||||
m = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
em = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
||||||
mp_set_int(&b, labs(m));
|
mp_set_int(&b, labs(em));
|
||||||
if (m < 0)
|
if (em < 0)
|
||||||
mp_neg(&b, &b);
|
mp_neg(&b, &b);
|
||||||
|
|
||||||
mp_set_int(&d, labs(l | m));
|
mp_set_int(&d, labs(l | em));
|
||||||
if ((l | m) < 0)
|
if ((l | em) < 0)
|
||||||
mp_neg(&d, &d);
|
mp_neg(&d, &d);
|
||||||
|
|
||||||
mp_tc_or(&a, &b, &c);
|
mp_tc_or(&a, &b, &c);
|
||||||
@ -359,20 +359,20 @@ int main(void)
|
|||||||
/* test mp_tc_and */
|
/* test mp_tc_and */
|
||||||
printf("\n\nTesting: mp_tc_and");
|
printf("\n\nTesting: mp_tc_and");
|
||||||
for (i = 0; i < 1000; ++i) {
|
for (i = 0; i < 1000; ++i) {
|
||||||
int l, m;
|
int l, em;
|
||||||
|
|
||||||
l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
||||||
mp_set_int(&a, labs(l));
|
mp_set_int(&a, labs(l));
|
||||||
if (l < 0)
|
if (l < 0)
|
||||||
mp_neg(&a, &a);
|
mp_neg(&a, &a);
|
||||||
|
|
||||||
m = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
em = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
|
||||||
mp_set_int(&b, labs(m));
|
mp_set_int(&b, labs(em));
|
||||||
if (m < 0)
|
if (em < 0)
|
||||||
mp_neg(&b, &b);
|
mp_neg(&b, &b);
|
||||||
|
|
||||||
mp_set_int(&d, labs(l & m));
|
mp_set_int(&d, labs(l & em));
|
||||||
if ((l & m) < 0)
|
if ((l & em) < 0)
|
||||||
mp_neg(&d, &d);
|
mp_neg(&d, &d);
|
||||||
|
|
||||||
mp_tc_and(&a, &b, &c);
|
mp_tc_and(&a, &b, &c);
|
||||||
|
Loading…
Reference in New Issue
Block a user