Merge pull request #476 from libtom/fix-double-check

Build+test bn_mp_set_double.c on more platforms
This commit is contained in:
Steffen Jaeckel 2020-03-05 14:25:43 +01:00 committed by GitHub
commit ce4e6ae114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 8 deletions

View File

@ -522,19 +522,24 @@ LBL_ERR:
}
#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();
@ -552,6 +557,9 @@ LBL_ERR:
return EXIT_FAILURE;
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif
static int test_mp_get_u32(void)
@ -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),

View File

@ -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;

View File

@ -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);