1 /* Square root of long double (ldbl-128) value, narrowing the result to
2 double, using soft-fp.
3 Copyright (C) 2021-2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20 #define f32xsqrtf64x __hide_f32xsqrtf64x
21 #define f32xsqrtf128 __hide_f32xsqrtf128
22 #define f64sqrtf64x __hide_f64sqrtf64x
23 #define f64sqrtf128 __hide_f64sqrtf128
24 #include <math.h>
25 #undef f32xsqrtf64x
26 #undef f32xsqrtf128
27 #undef f64sqrtf64x
28 #undef f64sqrtf128
29
30 #include <math-narrow.h>
31 #include <libc-diag.h>
32
33 /* Some components of the result's significand and exponent are not
34 set in cases where they are not used in packing, but the compiler
35 does not see that they are set in all cases where they are used,
36 resulting in warnings that they may be used uninitialized. */
37 DIAG_PUSH_NEEDS_COMMENT;
38 DIAG_IGNORE_NEEDS_COMMENT (7, "-Wmaybe-uninitialized");
39 #include <soft-fp.h>
40 #include <double.h>
41 #include <quad.h>
42
43 double
__dsqrtl(_Float128 x)44 __dsqrtl (_Float128 x)
45 {
46 FP_DECL_EX;
47 FP_DECL_Q (X);
48 FP_DECL_Q (R);
49 FP_DECL_D (RN);
50 double ret;
51
52 FP_INIT_ROUNDMODE;
53 FP_UNPACK_Q (X, x);
54 FP_SQRT_Q (R, X);
55 #if _FP_W_TYPE_SIZE < 64
56 FP_TRUNC_COOKED (D, Q, 2, 4, RN, R);
57 #else
58 FP_TRUNC_COOKED (D, Q, 1, 2, RN, R);
59 #endif
60 FP_PACK_D (ret, RN);
61 FP_HANDLE_EXCEPTIONS;
62 CHECK_NARROW_SQRT (ret, x);
63 return ret;
64 }
65 DIAG_POP_NEEDS_COMMENT;
66
67 libm_alias_double_ldouble (sqrt)
68