File procps-ng-3.3.12-strtod.patch of Package procps
---
include/strutils.h | 2 +-
lib/strutils.c | 22 ++++++++++++----------
lib/test_strtod_nol.c | 7 ++++---
3 files changed, 17 insertions(+), 14 deletions(-)
--- include/strutils.h
+++ include/strutils.h 2016-07-12 16:28:56.748950404 +0000
@@ -7,6 +7,6 @@
extern long strtol_or_err(const char *str, const char *errmesg);
extern double strtod_or_err(const char *str, const char *errmesg);
-double strtod_nol_or_err(char *str, const char *errmesg);
+extern double strtod_nol_or_err(char *str, const char *errmesg);
#endif
--- lib/strutils.c
+++ lib/strutils.c 2016-07-13 06:49:41.641951219 +0000
@@ -20,6 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <float.h>
+#include <math.h>
#include <stdlib.h>
#include <ctype.h>
@@ -71,9 +73,9 @@ double strtod_or_err(const char *str, co
*/
double strtod_nol_or_err(char *str, const char *errmesg)
{
- double num;
+ long double num;
const char *cp, *radix;
- double mult;
+ long double mult;
int negative = 0;
if (str != NULL && *str != '\0') {
@@ -95,29 +97,29 @@ double strtod_nol_or_err(char *str, cons
mult=0.1;
while(isdigit(*radix)) {
radix++;
- mult *= 10;
+ mult *= 10.0;
}
while(isdigit(*cp)) {
- num += (*cp - '0') * mult;
- mult /= 10;
+ num += (long double)(*cp - '0') * mult;
+ mult /= 10.0;
cp++;
}
/* got the integers */
if (*cp == '\0')
- return (negative?-num:num);
+ return (double)(negative?-num:num);
if (*cp != '.' && *cp != ',')
error(EXIT_FAILURE, EINVAL, "%s: '%s'", errmesg, str);
cp++;
mult = 0.1;
while(isdigit(*cp)) {
- num += (*cp - '0') * mult;
- mult /= 10;
+ num += (long double)(*cp - '0') * mult;
+ mult /= 10.0;
cp++;
}
if (*cp == '\0')
- return (negative?-num:num);
+ return (double)(negative?-num:num);
}
error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
- return 0;
+ return (double)0;
}
--- lib/test_strtod_nol.c
+++ lib/test_strtod_nol.c 2016-07-13 07:01:43.887513423 +0000
@@ -1,4 +1,5 @@
-
+#include <float.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "strutils.h"
@@ -33,8 +34,8 @@ int main(int argc, char *argv[])
double val;
for(i=0; tests[i].string != NULL; i++) {
- if(strtod_nol_or_err(tests[i].string, "Cannot parse number") !=
- tests[i].result) {
+ val = strtod_nol_or_err(tests[i].string, "Cannot parse number");
+ if(fabs(tests[i].result - val) > DBL_EPSILON) {
fprintf(stderr, "FAIL: strtod_nol_or_err(\"%s\") != %f\n",
tests[i].string, tests[i].result);
return EXIT_FAILURE;