Merge pull request #578 from PX4/fix_mp_prime_strong_lucas_lefridge_compilation
[libtommath.git] / mp_signed_rsh.c
blob3b7e232e530f484f42475b48b25776cf4b87b7a7
1 #include "tommath_private.h"
2 #ifdef MP_SIGNED_RSH_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* shift right by a certain bit count with sign extension */
7 mp_err mp_signed_rsh(const mp_int *a, int b, mp_int *c)
9 mp_err err;
10 if (!mp_isneg(a)) {
11 return mp_div_2d(a, b, c, NULL);
14 if ((err = mp_add_d(a, 1uL, c)) != MP_OKAY) {
15 return err;
18 err = mp_div_2d(c, b, c, NULL);
19 return (err == MP_OKAY) ? mp_sub_d(c, 1uL, c) : err;
21 #endif