From 0d62e8308ced6b8d81a338ac1979656255caba41 Mon Sep 17 00:00:00 2001 From: Etienne Brateau <etienne.brateau@ensiie.fr> Date: Wed, 11 Jul 2018 21:44:39 +0200 Subject: [PATCH] math: use size_t types instead of long, and remove some warnings --- psys/include/p2c/math.h | 6 +++--- psys/src/math.c | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/psys/include/p2c/math.h b/psys/include/p2c/math.h index b5aebcc..845b1c4 100644 --- a/psys/include/p2c/math.h +++ b/psys/include/p2c/math.h @@ -160,12 +160,12 @@ extern ma_complex ma_carcsinh (ma_complex a); extern ma_complex ma_carccosh (ma_complex a); extern ma_complex ma_carctanh (ma_complex a); extern char *ma_strcomplex (char *ma_Result, ma_complex a); -extern char *ma_strfmtcomplex (char *ma_Result, ma_complex a, long wid, +extern char *ma_strfmtcomplex (char *ma_Result, ma_complex a, size_t wid, long prec); -extern char *ma_strfmtcomplex2 (char *ma_Result, ma_complex a, long wid, +extern char *ma_strfmtcomplex2 (char *ma_Result, ma_complex a, size_t wid, long prec, long flags, double min, double max); -extern void ma_strsubreadcomplex (char *buf, long first, long *pos, +extern void ma_strsubreadcomplex (char *buf, size_t first, size_t *pos, ma_complex *a); extern ma_complex ma_strreadcomplex (char *buf); extern double ma_rrand () DEPRECATED; diff --git a/psys/src/math.c b/psys/src/math.c index 5fc5088..7be9e5c 100644 --- a/psys/src/math.c +++ b/psys/src/math.c @@ -1955,13 +1955,13 @@ ma_complex ma_carctanh(ma_complex a) } -char *ma_strfmtcomplex2(char *ma_Result, ma_complex a, long wid, long prec, long flags, double min, double max) +char *ma_strfmtcomplex2(char *ma_Result, ma_complex a, size_t wid, long prec, long flags, double min, double max) { char buf[256], buf2[256]; long i; int rz, iz, flag, usespace, useparen; long FORLIM; - char STR1[256]; + char STR1[268]; formatreal(buf, a.re, -1L, prec, flags, min, max); formatreal(buf2, a.im, -1L, prec, flags, min, max); @@ -2031,14 +2031,14 @@ char *ma_strfmtcomplex2(char *ma_Result, ma_complex a, long wid, long prec, long strcat(buf, buf2); } if (strlen(buf) < wid) { - sprintf(STR1, "%*s%s", (int)(wid - strlen(buf)), "", buf); + sprintf(STR1, "%ti%s%s", (ptrdiff_t)(wid - strlen(buf)), "", buf); strcpy(buf, STR1); } return strcpy(ma_Result, buf); } -char *ma_strfmtcomplex(char *ma_Result, ma_complex a, long wid, long prec) +char *ma_strfmtcomplex(char *ma_Result, ma_complex a, size_t wid, long prec) { return (ma_strfmtcomplex2(ma_Result, a, wid, prec, 0L, 1e-2, 0.0)); } @@ -2053,7 +2053,7 @@ char *ma_strcomplex(char *ma_Result, ma_complex a) struct LOC_ma_strsubreadcomplex { char *buf; double sign; - long i; + size_t i; } ; void skipspc(struct LOC_ma_strsubreadcomplex *LINK) @@ -2080,12 +2080,12 @@ void getsign(struct LOC_ma_strsubreadcomplex *LINK) LINK->sign = -1.0; } -void ma_strsubreadcomplex(char *buf_, long first, long *pos, ma_complex *a) +void ma_strsubreadcomplex(char *buf_, size_t first, size_t *pos, ma_complex *a) { struct LOC_ma_strsubreadcomplex V; double r; ma_complex val; - long j; + size_t j; int comma, parens, hasleft; char *STR1; @@ -2198,7 +2198,7 @@ ma_complex ma_strreadcomplex(char *buf_) { char buf[256]; ma_complex c; - long i; + size_t i; strcpy(buf, buf_); ma_strsubreadcomplex(buf, 1L, &i, &c); @@ -2294,7 +2294,8 @@ double ma_rrandom(void *s, double min, double max) long ma_irandom(void *s, long min, long max) { - long i, diff; + size_t i; + ptrdiff_t diff; rstaterec *WITH; if (max <= min) -- GitLab