Commit eb70378bfb39906f97874904ce17380e13539ac4

Daniel Mendler 2019-10-23T20:06:33

mp_iseven/mp_isodd should be inline

diff --git a/mp_iseven.c b/mp_iseven.c
deleted file mode 100644
index 4ebc9af..0000000
--- a/mp_iseven.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include "tommath_private.h"
-#ifdef MP_ISEVEN_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-mp_bool mp_iseven(const mp_int *a)
-{
-   return MP_IS_EVEN(a) ? MP_YES : MP_NO;
-}
-#endif
diff --git a/mp_isodd.c b/mp_isodd.c
deleted file mode 100644
index f8a3e0e..0000000
--- a/mp_isodd.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include "tommath_private.h"
-#ifdef MP_ISODD_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-mp_bool mp_isodd(const mp_int *a)
-{
-   return MP_IS_ODD(a) ? MP_YES : MP_NO;
-}
-#endif
diff --git a/tommath.h b/tommath.h
index f7711e1..5d0d2fe 100644
--- a/tommath.h
+++ b/tommath.h
@@ -209,9 +209,9 @@ mp_err mp_init_size(mp_int *a, int size) MP_WUR;
 
 /* ---> Basic Manipulations <--- */
 #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
-mp_bool mp_iseven(const mp_int *a) MP_WUR;
-mp_bool mp_isodd(const mp_int *a) MP_WUR;
 #define mp_isneg(a)  (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
+#define mp_iseven(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u) ? MP_YES : MP_NO)
+#define mp_isodd(a)  (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u) ? MP_YES : MP_NO)
 
 /* set to zero */
 void mp_zero(mp_int *a);