[ASan/Win tests] Bring back -GS- as SEH tests fail otherwise
[blocksruntime.git] / lib / builtins / divsc3.c
blob710d5320803fb8ded3dddea58396922f35f54fc0
1 /*===-- divsc3.c - Implement __divsc3 -------------------------------------===
3 * The LLVM Compiler Infrastructure
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
8 * ===----------------------------------------------------------------------===
10 * This file implements __divsc3 for the compiler_rt library.
12 *===----------------------------------------------------------------------===
15 #include "int_lib.h"
16 #include "int_math.h"
18 /* Returns: the quotient of (a + ib) / (c + id) */
20 COMPILER_RT_ABI float _Complex
21 __divsc3(float __a, float __b, float __c, float __d)
23 int __ilogbw = 0;
24 float __logbw = crt_logbf(crt_fmaxf(crt_fabsf(__c), crt_fabsf(__d)));
25 if (crt_isfinite(__logbw))
27 __ilogbw = (int)__logbw;
28 __c = crt_scalbnf(__c, -__ilogbw);
29 __d = crt_scalbnf(__d, -__ilogbw);
31 float __denom = __c * __c + __d * __d;
32 float _Complex z;
33 __real__ z = crt_scalbnf((__a * __c + __b * __d) / __denom, -__ilogbw);
34 __imag__ z = crt_scalbnf((__b * __c - __a * __d) / __denom, -__ilogbw);
35 if (crt_isnan(__real__ z) && crt_isnan(__imag__ z))
37 if ((__denom == 0) && (!crt_isnan(__a) || !crt_isnan(__b)))
39 __real__ z = crt_copysignf(CRT_INFINITY, __c) * __a;
40 __imag__ z = crt_copysignf(CRT_INFINITY, __c) * __b;
42 else if ((crt_isinf(__a) || crt_isinf(__b)) &&
43 crt_isfinite(__c) && crt_isfinite(__d))
45 __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a);
46 __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b);
47 __real__ z = CRT_INFINITY * (__a * __c + __b * __d);
48 __imag__ z = CRT_INFINITY * (__b * __c - __a * __d);
50 else if (crt_isinf(__logbw) && __logbw > 0 &&
51 crt_isfinite(__a) && crt_isfinite(__b))
53 __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c);
54 __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d);
55 __real__ z = 0 * (__a * __c + __b * __d);
56 __imag__ z = 0 * (__b * __c - __a * __d);
59 return z;