Avoid float errors on 32bit architectures

OBS-URL: https://build.opensuse.org/package/show/Base:System/procps?expand=0&rev=230
This commit is contained in:
Dr. Werner Fink 2022-03-30 09:24:59 +00:00 committed by Git OBS Bridge
parent 2c5deae810
commit 2c837846a7
3 changed files with 75 additions and 1 deletions

View File

@ -0,0 +1,65 @@
---
lib/strutils.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
--- lib/strutils.c
+++ lib/strutils.c 2021-02-09 10:11:25.000000000 +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;
}

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Mar 30 09:23:58 UTC 2022 - Dr. Werner Fink <werner@suse.de>
- Add patch procps-ng-4.0.0-floats.dif to avoid float errors on
32bit architectures
-------------------------------------------------------------------
Wed Mar 30 09:12:42 UTC 2022 - Dr. Werner Fink <werner@suse.de>

View File

@ -60,6 +60,8 @@ Patch32: procps-ng-3.3.10-errno.patch
Patch33: procps-ng-3.3.11-pmap4suse.patch
# PATCH-FIX-SUSE -- Avoid error on AIX sort formats
Patch34: procps-ng-4.0.0-aix_sortformats.dif
# PATCH-FIX-SUSE -- Avoid float errors on 32bit architectures
Patch35: procps-ng-4.0.0-floats.dif
BuildRequires: automake
BuildRequires: dejagnu
BuildRequires: diffutils
@ -137,7 +139,8 @@ the process information pseudo-file system.
%patch31 -p1
%patch32
%patch33 -b .pmap4us
%patch34 -b .aix
%patch34
%patch35
%build
test -s .tarball-version || echo %{version} > .tarball-version