translations: update cs, nl, vi
[glibc.git] / math / multc3.c
blob614b21b210b950b8862227e5820f6eb65e0e57bd
1 /* Copyright (C) 2005-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <stdbool.h>
19 #include <math.h>
20 #include <complex.h>
22 attribute_hidden
23 long double _Complex
24 __multc3 (long double a, long double b, long double c, long double d)
26 long double ac, bd, ad, bc, x, y;
28 ac = a * c;
29 bd = b * d;
30 ad = a * d;
31 bc = b * c;
33 x = ac - bd;
34 y = ad + bc;
36 if (isnan (x) && isnan (y))
38 /* Recover infinities that computed as NaN + iNaN. */
39 bool recalc = 0;
40 if (isinf (a) || isinf (b))
42 /* z is infinite. "Box" the infinity and change NaNs in
43 the other factor to 0. */
44 a = copysignl (isinf (a) ? 1 : 0, a);
45 b = copysignl (isinf (b) ? 1 : 0, b);
46 if (isnan (c)) c = copysignl (0, c);
47 if (isnan (d)) d = copysignl (0, d);
48 recalc = 1;
50 if (isinf (c) || isinf (d))
52 /* w is infinite. "Box" the infinity and change NaNs in
53 the other factor to 0. */
54 c = copysignl (isinf (c) ? 1 : 0, c);
55 d = copysignl (isinf (d) ? 1 : 0, d);
56 if (isnan (a)) a = copysignl (0, a);
57 if (isnan (b)) b = copysignl (0, b);
58 recalc = 1;
60 if (!recalc
61 && (isinf (ac) || isinf (bd)
62 || isinf (ad) || isinf (bc)))
64 /* Recover infinities from overflow by changing NaNs to 0. */
65 if (isnan (a)) a = copysignl (0, a);
66 if (isnan (b)) b = copysignl (0, b);
67 if (isnan (c)) c = copysignl (0, c);
68 if (isnan (d)) d = copysignl (0, d);
69 recalc = 1;
71 if (recalc)
73 x = INFINITY * (a * c - b * d);
74 y = INFINITY * (a * d + b * c);
78 return x + I * y;