Skip to content
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

Build+test bn_mp_set_double.c on more platforms #476

Merged
merged 3 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions demo/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,19 +522,24 @@ static int test_mp_invmod(void)

}

#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559)
#if defined(MP_HAS_SET_DOUBLE)

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4723) /* potential divide by 0 */
#endif
static int test_mp_set_double(void)
{
int i;
double dbl_zero = 0.0;

mp_int a, b;
DOR(mp_init_multi(&a, &b, NULL));

/* test mp_get_double/mp_set_double */
EXPECT(mp_set_double(&a, +1.0/0.0) == MP_VAL);
EXPECT(mp_set_double(&a, -1.0/0.0) == MP_VAL);
EXPECT(mp_set_double(&a, +0.0/0.0) == MP_VAL);
EXPECT(mp_set_double(&a, -0.0/0.0) == MP_VAL);
EXPECT(mp_set_double(&a, +1.0/dbl_zero) == MP_VAL);
EXPECT(mp_set_double(&a, -1.0/dbl_zero) == MP_VAL);
EXPECT(mp_set_double(&a, +0.0/dbl_zero) == MP_VAL);
EXPECT(mp_set_double(&a, -0.0/dbl_zero) == MP_VAL);

for (i = 0; i < 1000; ++i) {
int tmp = rand_int();
Expand All @@ -552,6 +557,9 @@ static int test_mp_set_double(void)
return EXIT_FAILURE;

}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif

static int test_mp_get_u32(void)
Expand Down Expand Up @@ -2164,7 +2172,7 @@ static int unit_tests(int argc, char **argv)
T1(mp_reduce_2k_l, MP_REDUCE_2K_L),
T1(mp_radix_size, MP_RADIX_SIZE),
T1(s_mp_radix_size_overestimate, S_MP_RADIX_SIZE_OVERESTIMATE),
#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559)
#if defined(MP_HAS_SET_DOUBLE)
T1(mp_set_double, MP_SET_DOUBLE),
#endif
T1(mp_signed_rsh, MP_SIGNED_RSH),
Expand Down
2 changes: 1 addition & 1 deletion mp_set_double.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */

#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559)
#if defined(MP_HAS_SET_DOUBLE)
mp_err mp_set_double(mp_int *a, double b)
{
uint64_t frac;
Expand Down
7 changes: 7 additions & 0 deletions tommath_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ MP_STATIC_ASSERT(prec_geq_min_prec, MP_DEFAULT_DIGIT_COUNT >= MP_MIN_DIGIT_COUNT
*/
#define MP_MAX_DIGIT_COUNT ((INT_MAX - 2) / MP_DIGIT_BIT)

#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) \
|| defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) \
|| defined(__i386__) || defined(_M_X86) \
|| defined(__aarch64__) || defined(__arm__)
#define MP_HAS_SET_DOUBLE
#endif

/* random number source */
extern MP_PRIVATE mp_err(*s_mp_rand_source)(void *out, size_t size);

Expand Down