]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/ldbl-128ibm/test-fmodrem-ldbl-128ibm.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / ieee754 / ldbl-128ibm / test-fmodrem-ldbl-128ibm.c
1 /* Test for ldbl-128ibm fmodl etc. handling of equal values.
2 Copyright (C) 2016-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <fenv.h>
20 #include <float.h>
21 #include <math.h>
22 #include <stdio.h>
23
24 /* FUNC is defined to be the name of the function to test. */
25 #define STRX(x) #x
26 #define STR(x) STRX (x)
27 #define SFUNC STR (FUNC)
28
29 union u
30 {
31 long double ld;
32 double d[2];
33 };
34
35 volatile union u p1 = { .d = { DBL_MIN, 0.0 } };
36 volatile union u p2 = { .d = { DBL_MIN, -0.0 } };
37 volatile union u m1 = { .d = { -DBL_MIN, 0.0 } };
38 volatile union u m2 = { .d = { -DBL_MIN, -0.0 } };
39
40 static int
41 test_func (const char *s, long double x, long double y, long double expected)
42 {
43 volatile long double r;
44 r = FUNC (x, y);
45 if (r != expected || copysignl (1.0, r) != copysignl (1.0, expected))
46 {
47 printf ("FAIL: " SFUNC " (%s)\n", s);
48 return 1;
49 }
50 else
51 {
52 printf ("PASS: " SFUNC " (%s)\n", s);
53 return 0;
54 }
55 }
56
57 #define TEST_FUNC(a, b, e) test_func (#a ", " #b, a, b, e)
58
59 static int
60 do_test (void)
61 {
62 int result = 0;
63 SETUP;
64 result |= TEST_FUNC (p1.ld, p1.ld, 0.0L);
65 result |= TEST_FUNC (p1.ld, p2.ld, 0.0L);
66 result |= TEST_FUNC (p1.ld, m1.ld, 0.0L);
67 result |= TEST_FUNC (p1.ld, m2.ld, 0.0L);
68 result |= TEST_FUNC (p2.ld, p1.ld, 0.0L);
69 result |= TEST_FUNC (p2.ld, p2.ld, 0.0L);
70 result |= TEST_FUNC (p2.ld, m1.ld, 0.0L);
71 result |= TEST_FUNC (p2.ld, m2.ld, 0.0L);
72 result |= TEST_FUNC (m1.ld, p1.ld, -0.0L);
73 result |= TEST_FUNC (m1.ld, p2.ld, -0.0L);
74 result |= TEST_FUNC (m1.ld, m1.ld, -0.0L);
75 result |= TEST_FUNC (m1.ld, m2.ld, -0.0L);
76 result |= TEST_FUNC (m2.ld, p1.ld, -0.0L);
77 result |= TEST_FUNC (m2.ld, p2.ld, -0.0L);
78 result |= TEST_FUNC (m2.ld, m1.ld, -0.0L);
79 result |= TEST_FUNC (m2.ld, m2.ld, -0.0L);
80 return result;
81 }
82
83 #define TEST_FUNCTION do_test ()
84 #include "../../../test-skeleton.c"