From 869de6d8e3833932ee8b0e8e70c13a2e5d4ceb82 Mon Sep 17 00:00:00 2001 From: mbkma Date: Sun, 25 Oct 2020 14:54:31 +0100 Subject: Fix most conversion warnings. --- src/financial.c | 5 ++-- src/mate-calc-cmd.c | 3 +-- src/mp-convert.c | 13 +++++----- src/mp-serializer.c | 5 ++-- src/mp.c | 69 +++++++++++++++++++++++++---------------------------- src/mp.h | 10 ++++---- src/parser.c | 2 +- src/parserfunc.c | 2 +- 8 files changed, 53 insertions(+), 56 deletions(-) diff --git a/src/financial.c b/src/financial.c index 337ff93..aa47dd0 100644 --- a/src/financial.c +++ b/src/financial.c @@ -60,15 +60,14 @@ calc_ddb(MathEquation *equation, MPNumber *t, MPNumber *cost, MPNumber *life, MP * */ - int i; - int len; + long len; MPNumber MPbv = mp_new(); MPNumber MP1 = mp_new(); MPNumber MP2 = mp_new(); mp_set_from_integer(0, &MPbv); len = mp_to_integer(period); - for (i = 0; i < len; i++) { + for (long i = 0; i < len; i++) { mp_subtract(cost, &MPbv, &MP1); mp_multiply_integer(&MP1, 2, &MP2); mp_divide(&MP2, life, t); diff --git a/src/mate-calc-cmd.c b/src/mate-calc-cmd.c index cf8db3d..d8e86ec 100644 --- a/src/mate-calc-cmd.c +++ b/src/mate-calc-cmd.c @@ -70,7 +70,6 @@ int main(int argc, char **argv) { char *equation, *line; - size_t nbytes = MAXLINE; /* Seed random number generator. */ srand48((long) time((time_t *) 0)); @@ -82,7 +81,7 @@ main(int argc, char **argv) equation = (char *) malloc(MAXLINE * sizeof(char)); while (1) { printf("> "); - line = fgets(equation, nbytes, stdin); + line = fgets(equation, MAXLINE, stdin); if (line != NULL) str_adjust(equation); diff --git a/src/mp-convert.c b/src/mp-convert.c index ef1a770..c0a88c1 100644 --- a/src/mp-convert.c +++ b/src/mp-convert.c @@ -33,21 +33,21 @@ mp_set_from_double(double dx, MPNumber *z) void -mp_set_from_integer(int64_t x, MPNumber *z) +mp_set_from_integer(long x, MPNumber *z) { mpc_set_si(z->num, x, MPC_RNDNN); } void -mp_set_from_unsigned_integer(uint64_t x, MPNumber *z) +mp_set_from_unsigned_integer(ulong x, MPNumber *z) { mpc_set_ui(z->num, x, MPC_RNDNN); } void -mp_set_from_fraction(int64_t numerator, int64_t denominator, MPNumber *z) +mp_set_from_fraction(long numerator, long denominator, MPNumber *z) { if (denominator < 0) { numerator = -numerator; @@ -88,14 +88,14 @@ mp_set_from_random(MPNumber *z) mp_set_from_double(drand48(), z); } -int64_t +long mp_to_integer(const MPNumber *x) { return mpfr_get_si(mpc_realref(x->num), MPFR_RNDN); } -uint64_t +ulong mp_to_unsigned_integer(const MPNumber *x) { return mpfr_get_ui(mpc_realref(x->num), MPFR_RNDN); @@ -116,7 +116,8 @@ mp_to_double(const MPNumber *x) static int char_val(char **c, int base) { - int i, j, value, offset; + int i, j, value; + size_t offset; const char *digits[][10] = {{"٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"}, {"〇", "〡", "〢", "〣", "〤", "〥", "〦", "〧", "〨", "〩"}, {"۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"}, diff --git a/src/mp-serializer.c b/src/mp-serializer.c index 3967cbc..366355f 100644 --- a/src/mp-serializer.c +++ b/src/mp-serializer.c @@ -63,7 +63,8 @@ mp_to_string_real(MpSerializer *serializer, const MPNumber *x, int base, gboolea MPNumber integer_component = mp_new(); MPNumber fractional_component = mp_new(); MPNumber temp = mp_new(); - int i, last_non_zero; + int i; + gsize last_non_zero; if (mp_is_negative(x)) mp_abs(x, &number); @@ -92,7 +93,7 @@ mp_to_string_real(MpSerializer *serializer, const MPNumber *x, int base, gboolea MPNumber t = mp_new(); MPNumber t2 = mp_new(); MPNumber t3 = mp_new(); - int64_t d; + long d; if (serializer->priv->base == 10 && serializer->priv->show_tsep && i == serializer->priv->tsep_count) { g_string_prepend_unichar(string, serializer->priv->tsep); diff --git a/src/mp.c b/src/mp.c index 6563b90..1f3965e 100644 --- a/src/mp.c +++ b/src/mp.c @@ -37,14 +37,12 @@ mperr(const char *format, ...) mp_error = strdup(text); } - const char * mp_get_error() { return mp_error; } - void mp_clear_error() { if (mp_error) @@ -52,7 +50,6 @@ void mp_clear_error() mp_error = NULL; } - MPNumber mp_new(void) { @@ -62,11 +59,11 @@ mp_new(void) } MPNumber -mp_new_from_integer(uint64_t x) +mp_new_from_unsigned_integer(ulong x) { MPNumber z; mpc_init2(z.num, PRECISION); - mpc_set_si(z.num, x, MPC_RNDNN); + mpc_set_ui(z.num, x, MPC_RNDNN); return z; } @@ -163,7 +160,7 @@ mp_add(const MPNumber *x, const MPNumber *y, MPNumber *z) } void -mp_add_integer(const MPNumber *x, int64_t y, MPNumber *z) +mp_add_integer(const MPNumber *x, long y, MPNumber *z) { mpc_add_si(z->num, x->num, y, MPC_RNDNN); } @@ -244,7 +241,7 @@ mp_divide(const MPNumber *x, const MPNumber *y, MPNumber *z) } void -mp_divide_integer(const MPNumber *x, int64_t y, MPNumber *z) +mp_divide_integer(const MPNumber *x, long y, MPNumber *z) { MPNumber t1 = mp_new(); @@ -365,7 +362,7 @@ mp_ln(const MPNumber *x, MPNumber *z) } void -mp_logarithm(int64_t n, const MPNumber *x, MPNumber *z) +mp_logarithm(long n, const MPNumber *x, MPNumber *z) { /* log(0) undefined */ if (mp_is_zero(x)) @@ -392,9 +389,9 @@ mp_multiply(const MPNumber *x, const MPNumber *y, MPNumber *z) } void -mp_multiply_integer(const MPNumber *x, int64_t y, MPNumber *z) +mp_multiply_integer(const MPNumber *x, long y, MPNumber *z) { - mpc_mul_si(z->num, x->num, (long) y, MPC_RNDNN); + mpc_mul_si(z->num, x->num, y, MPC_RNDNN); } void @@ -411,18 +408,18 @@ mp_reciprocal(const MPNumber *x, MPNumber *z) } void -mp_root(const MPNumber *x, int64_t n, MPNumber *z) +mp_root(const MPNumber *x, long n, MPNumber *z) { - uint64_t p; + ulong p; if (n < 0) { mpc_ui_div(z->num, 1, x->num, MPC_RNDNN); - if (n == INT64_MIN) - p = (uint64_t) INT64_MAX + 1; + if (n == LONG_MIN) + p = (ulong) LONG_MAX + 1; else - p = -n; + p = (ulong) -n; } else if (n > 0) { @@ -437,14 +434,14 @@ mp_root(const MPNumber *x, int64_t n, MPNumber *z) } if (!mp_is_complex(x) && (!mp_is_negative(x) || (p & 1) == 1)) { - mpfr_rootn_ui(mpc_realref(z->num), mpc_realref(z->num), (uint64_t) p, MPFR_RNDN); + mpfr_rootn_ui(mpc_realref(z->num), mpc_realref(z->num), p, MPFR_RNDN); mpfr_set_zero(mpc_imagref(z->num), MPFR_RNDN); } else { mpfr_t tmp; mpfr_init2(tmp, PRECISION); - mpfr_set_ui(tmp, (uint64_t) p, MPFR_RNDN); + mpfr_set_ui(tmp, p, MPFR_RNDN); mpfr_ui_div(tmp, 1, tmp, MPFR_RNDN); mpc_pow_fr(z->num, z->num, tmp, MPC_RNDNN); mpfr_clear(tmp); @@ -490,7 +487,7 @@ mp_factorial(const MPNumber *x, MPNumber *z) else { /* Convert to integer - if couldn't be converted then the factorial would be too big anyway */ - int64_t value = mp_to_integer(x); + ulong value = mp_to_unsigned_integer(x); mpfr_fac_ui(mpc_realref(z->num), value, MPFR_RNDN); mpfr_set_zero(mpc_imagref(z->num), MPFR_RNDN); } @@ -594,7 +591,7 @@ mp_xpowy(const MPNumber *x, const MPNumber *y, MPNumber *z) } void -mp_xpowy_integer(const MPNumber *x, int64_t n, MPNumber *z) +mp_xpowy_integer(const MPNumber *x, long n, MPNumber *z) { /* 0^-n invalid */ if (mp_is_zero(x) && n < 0) @@ -604,7 +601,7 @@ mp_xpowy_integer(const MPNumber *x, int64_t n, MPNumber *z) return; } - mpc_pow_si(z->num, x->num, (long) n, MPC_RNDNN); + mpc_pow_si(z->num, x->num, n, MPC_RNDNN); } void @@ -656,11 +653,11 @@ mp_zeta(const MPNumber *x, MPNumber *z) * Returns TRUE if @n is probable prime and FALSE otherwise. */ static bool -mp_is_pprime(MPNumber *n, uint64_t rounds) +mp_is_pprime(MPNumber *n, ulong rounds) { MPNumber tmp = mp_new(); - MPNumber two = mp_new_from_integer(2); - uint64_t l = 0; + MPNumber two = mp_new_from_unsigned_integer(2); + ulong l = 0; bool is_pprime = TRUE; /* Write t := n-1 = 2^l * q with q odd */ @@ -676,11 +673,11 @@ mp_is_pprime(MPNumber *n, uint64_t rounds) } while (mp_is_zero(&tmp)); /* @rounds Miller-Rabin tests to bases a = 2,3,...,@rounds+1 */ - MPNumber one = mp_new_from_integer(1); - MPNumber a = mp_new_from_integer(1); + MPNumber one = mp_new_from_unsigned_integer(1); + MPNumber a = mp_new_from_unsigned_integer(1); MPNumber b = mp_new(); - for (uint64_t i = 1; (i < mp_to_integer(&t)) && (i <= rounds+1); i++) + for (ulong i = 1; (i < mp_to_integer(&t)) && (i <= rounds+1); i++) { mp_add_integer(&a, 1, &a); mp_modular_exponentiation(&a, &q, n, &b); @@ -690,7 +687,7 @@ mp_is_pprime(MPNumber *n, uint64_t rounds) } bool is_witness = FALSE; - for (int i = 1; i < l; i++) + for (long j = 1; j < l; j++) { mp_modular_exponentiation(&b, &two, n, &b); if (mp_compare(&b, &t) == 0) @@ -724,7 +721,7 @@ mp_is_pprime(MPNumber *n, uint64_t rounds) static void mp_gcd (const MPNumber *a, const MPNumber *b, MPNumber *z) { - MPNumber null = mp_new_from_integer(0); + MPNumber null = mp_new_from_unsigned_integer(0); MPNumber t1 = mp_new(); MPNumber t2 = mp_new(); @@ -752,13 +749,13 @@ mp_gcd (const MPNumber *a, const MPNumber *b, MPNumber *z) * Returns FALSE otherwise. */ static bool -mp_pollard_rho (const MPNumber *n, uint64_t i, MPNumber *z) +mp_pollard_rho (const MPNumber *n, ulong i, MPNumber *z) { - MPNumber one = mp_new_from_integer(1); - MPNumber two = mp_new_from_integer(2); - MPNumber x = mp_new_from_integer(i); - MPNumber y = mp_new_from_integer(2); - MPNumber d = mp_new_from_integer(1); + MPNumber one = mp_new_from_unsigned_integer(1); + MPNumber two = mp_new_from_unsigned_integer(2); + MPNumber x = mp_new_from_unsigned_integer(i); + MPNumber y = mp_new_from_unsigned_integer(2); + MPNumber d = mp_new_from_unsigned_integer(1); while (mp_compare(&d, &one) == 0) { @@ -809,7 +806,7 @@ static void find_big_prime_factor (const MPNumber *n, MPNumber *z) { MPNumber tmp = mp_new(); - uint64_t i = 2; + ulong i = 2; while (TRUE) { @@ -886,7 +883,7 @@ mp_factorize(const MPNumber *x) return list; } - MPNumber divisor = mp_new_from_integer(2); + MPNumber divisor = mp_new_from_unsigned_integer(2); while (TRUE) { mp_divide(&value, &divisor, &tmp); diff --git a/src/mp.h b/src/mp.h index 8c527e3..22bc986 100644 --- a/src/mp.h +++ b/src/mp.h @@ -69,7 +69,7 @@ void mperr(const char *format, ...) __attribute__((format(printf, 1, 2))) /* Returns initialized MPNumber object */ MPNumber mp_new(void); -MPNumber mp_new_from_integer(uint64_t x); +MPNumber mp_new_from_unsigned_integer(ulong x); MPNumber* mp_new_ptr(void); @@ -195,7 +195,7 @@ void mp_get_eulers(MPNumber *z); void mp_get_i(MPNumber *z); /* Sets z = n√x */ -void mp_root(const MPNumber *x, int64_t n, MPNumber *z); +void mp_root(const MPNumber *x, long n, MPNumber *z); /* Sets z = √x */ void mp_sqrt(const MPNumber *x, MPNumber *z); @@ -213,7 +213,7 @@ void mp_modular_exponentiation(const MPNumber *x, const MPNumber *y, const MPNum void mp_xpowy(const MPNumber *x, const MPNumber *y, MPNumber *z); /* Sets z = x^y */ -void mp_xpowy_integer(const MPNumber *x, int64_t y, MPNumber *z); +void mp_xpowy_integer(const MPNumber *x, long y, MPNumber *z); /* Sets z = e^x */ void mp_epowy(const MPNumber *x, MPNumber *z); @@ -262,10 +262,10 @@ float mp_to_float(const MPNumber *x); double mp_to_double(const MPNumber *x); /* Returns x as a native integer */ -int64_t mp_to_integer(const MPNumber *x); +long mp_to_integer(const MPNumber *x); /* Returns x as a native unsigned integer */ -uint64_t mp_to_unsigned_integer(const MPNumber *x); +ulong mp_to_unsigned_integer(const MPNumber *x); /* Sets z = sin x */ void mp_sin(const MPNumber *x, MPAngleUnit unit, MPNumber *z); diff --git a/src/parser.c b/src/parser.c index b8cc98f..8ab4c3c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -347,7 +347,7 @@ p_check_variable(ParserState* state, gchar* name) for(c = name; *c != '\0'; c = next) { next = utf8_next_char(c); - snprintf(buffer, next - c + 1, "%s", c); + snprintf(buffer, (size_t) (next - c + 1), "%s", c); if(!(*(state->get_variable))(state, buffer, &temp)) { result = 0; diff --git a/src/parserfunc.c b/src/parserfunc.c index c63ff96..6f27daf 100644 --- a/src/parserfunc.c +++ b/src/parserfunc.c @@ -584,7 +584,7 @@ void* pf_do_x_pow_y_int(ParseNode* self) { MPNumber* val; - gint pow; + long pow; MPNumber* ans = mp_new_ptr(); val = (MPNumber*) (*(self->left->evaluate))(self->left); -- cgit v1.2.1