mirror of
https://github.com/systemd/systemd.git
synced 2024-10-31 07:51:21 +03:00
test: use fabs on doubles
This commit is contained in:
parent
21d73c87b0
commit
8e21100002
@ -26,6 +26,7 @@
|
||||
#include <locale.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "mkdir.h"
|
||||
@ -191,7 +192,7 @@ static void test_safe_atod(void) {
|
||||
|
||||
r = safe_atod("0.2244", &d);
|
||||
assert_se(r == 0);
|
||||
assert_se(abs(d - 0.2244) < 0.000001);
|
||||
assert_se(fabs(d - 0.2244) < 0.000001);
|
||||
|
||||
r = safe_atod("0,5", &d);
|
||||
assert_se(r == -EINVAL);
|
||||
@ -205,20 +206,20 @@ static void test_safe_atod(void) {
|
||||
|
||||
r = safe_atod("0.2244", &d);
|
||||
assert_se(r == 0);
|
||||
assert_se(abs(d - 0.2244) < 0.000001);
|
||||
assert_se(fabs(d - 0.2244) < 0.000001);
|
||||
|
||||
r = safe_atod("0,5", &d);
|
||||
assert_se(r == -EINVAL);
|
||||
|
||||
errno = 0;
|
||||
assert_se(abs(strtod("0,5", &e) - 0.5) < 0.00001);
|
||||
assert_se(fabs(strtod("0,5", &e) - 0.5) < 0.00001);
|
||||
|
||||
/* And check again, reset */
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
|
||||
r = safe_atod("0.2244", &d);
|
||||
assert_se(r == 0);
|
||||
assert_se(abs(d - 0.2244) < 0.000001);
|
||||
assert_se(fabs(d - 0.2244) < 0.000001);
|
||||
|
||||
r = safe_atod("0,5", &d);
|
||||
assert_se(r == -EINVAL);
|
||||
|
Loading…
Reference in New Issue
Block a user