using floor and ceil from math lib for rounding and truncation
This commit is contained in:
parent
15883a251d
commit
306291f426
|
|
@ -10,6 +10,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#ifdef HAS_WINDOWS
|
#ifdef HAS_WINDOWS
|
||||||
|
|
@ -72,7 +73,7 @@ wi (long i)
|
||||||
|
|
||||||
void
|
void
|
||||||
rs (char *s)
|
rs (char *s)
|
||||||
{ /*basic line input, limit= 80 chars */
|
{ /* basic line input, limit= 80 chars */
|
||||||
int max, i;
|
int max, i;
|
||||||
char c;
|
char c;
|
||||||
/* exit (-1); */
|
/* exit (-1); */
|
||||||
|
|
@ -962,8 +963,8 @@ posi (char *sub, char *s, int opt)
|
||||||
/* find position of substring in s */
|
/* find position of substring in s */
|
||||||
{
|
{
|
||||||
/* opt=0: like Turbo Pascal */
|
/* opt=0: like Turbo Pascal */
|
||||||
/* opt=1: like Turbo Pascal Pos, but case insensitive */
|
/* opt=1: like Turbo Pascal Pos, but case insensitive */
|
||||||
/* opt=2: position in space separated wordlist for scanners */
|
/* opt=2: position in space separated wordlist for scanners */
|
||||||
int a, b, k, j;
|
int a, b, k, j;
|
||||||
unsigned char ok, tstcase;
|
unsigned char ok, tstcase;
|
||||||
Str (250, t);
|
Str (250, t);
|
||||||
|
|
@ -984,7 +985,7 @@ posi (char *sub, char *s, int opt)
|
||||||
k = 0;
|
k = 0;
|
||||||
j = 1;
|
j = 1;
|
||||||
|
|
||||||
if (a > 0) /*;} else { return 0 */
|
if (a > 0) /* ;} else { return 0 */
|
||||||
while ((k <= b) && (!ok))
|
while ((k <= b) && (!ok))
|
||||||
{
|
{
|
||||||
ok = match (t, s, a, k, tstcase); /* we must start at k=0 ! */
|
ok = match (t, s, a, k, tstcase); /* we must start at k=0 ! */
|
||||||
|
|
@ -1035,7 +1036,7 @@ void
|
||||||
strf (double x, int f1, int f2, char *t)
|
strf (double x, int f1, int f2, char *t)
|
||||||
/* e-format if f2<0, else f2 digits after the point, total width=f1 */
|
/* e-format if f2<0, else f2 digits after the point, total width=f1 */
|
||||||
/* if f1=0, also e-format with f2 digits */
|
/* if f1=0, also e-format with f2 digits */
|
||||||
{ /*default f1=17, f2=-1 */
|
{ /* default f1=17, f2=-1 */
|
||||||
Str (30, fmt);
|
Str (30, fmt);
|
||||||
int n, mlt;
|
int n, mlt;
|
||||||
mlt = maxlen (t);
|
mlt = maxlen (t);
|
||||||
|
|
@ -1122,11 +1123,11 @@ ival (char *s, int *err)
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _MATH_H
|
#ifndef HAVE_LIBM
|
||||||
|
|
||||||
long
|
long
|
||||||
np_round (double x)
|
np_round (double x)
|
||||||
/* using <math.h>, it would be simpler: floor(x+0.5) */
|
/* using <math.h>, it would be simpler: floor(x+0.5), see below */
|
||||||
{
|
{
|
||||||
double u;
|
double u;
|
||||||
long z;
|
long z;
|
||||||
|
|
@ -1207,4 +1208,4 @@ intp (double x) /* integral part */
|
||||||
return ceil (x);
|
return ceil (x);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _MATH_H */
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue