From 5c4f5d9c0c3c5d9666ed1ba4e5d658abb3adc9fb Mon Sep 17 00:00:00 2001 From: czurnieden Date: Wed, 21 Jun 2023 14:10:44 +0200 Subject: [PATCH] added macro mp_isone --- doc/bn.tex | 6 ++++++ tommath.h | 1 + 2 files changed, 7 insertions(+) diff --git a/doc/bn.tex b/doc/bn.tex index 711ad0e5..0642263e 100644 --- a/doc/bn.tex +++ b/doc/bn.tex @@ -2658,6 +2658,12 @@ \section{Function Macros} \end{alltt} Checks if $a = 0$. It does not check if the amount of memory allocated for $a$ is also minimal. +\index{mp\_isone} +\begin{alltt} +bool mp_isone(mp_int *a) +\end{alltt} +Checks if $a = 1$. + Other macros which are either shortcuts to normal functions or just other names for them do have their place in a programmer's life, too! diff --git a/tommath.h b/tommath.h index 33aa5dfd..db005081 100644 --- a/tommath.h +++ b/tommath.h @@ -208,6 +208,7 @@ mp_err mp_init_size(mp_int *a, int size) MP_WUR; /* ---> Basic Manipulations <--- */ #define mp_iszero(a) ((a)->used == 0) +#define mp_isone(a) ( ((a)->sign == MP_ZPOS) && ((a)->used == 1u) && ((a)->dp[0] == 1u) ) #define mp_isneg(a) ((a)->sign == MP_NEG) #define mp_iseven(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u)) #define mp_isodd(a) (!mp_iseven(a))