PR target/60017
[official-gcc.git] / libgo / runtime / go-cdiv.c
blob0a81e458c84d35f69bf8d5ad06a5a5df27c574e8
1 /* go-cdiv.c -- complex division routines
3 Copyright 2013 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 /* Calls to these functions are generated by the Go frontend for
8 division of complex64 or complex128. We use these because Go's
9 complex division expects slightly different results from the GCC
10 default. When dividing NaN+1.0i / 0+0i, Go expects NaN+NaNi but
11 GCC generates NaN+Infi. NaN+Infi seems wrong seems the rules of
12 C99 Annex G specify that if either side of a complex number is Inf,
13 the the whole number is Inf, but an operation involving NaN ought
14 to result in NaN, not Inf. */
16 __complex float
17 __go_complex64_div (__complex float a, __complex float b)
19 if (__builtin_expect (b == 0+0i, 0))
21 if (!__builtin_isinff (__real__ a)
22 && !__builtin_isinff (__imag__ a)
23 && (__builtin_isnanf (__real__ a) || __builtin_isnanf (__imag__ a)))
25 /* Pass "1" to nanf to match math/bits.go. */
26 return __builtin_nanf("1") + __builtin_nanf("1")*1i;
29 return a / b;
32 __complex double
33 __go_complex128_div (__complex double a, __complex double b)
35 if (__builtin_expect (b == 0+0i, 0))
37 if (!__builtin_isinf (__real__ a)
38 && !__builtin_isinf (__imag__ a)
39 && (__builtin_isnan (__real__ a) || __builtin_isnan (__imag__ a)))
41 /* Pass "1" to nan to match math/bits.go. */
42 return __builtin_nan("1") + __builtin_nan("1")*1i;
45 return a / b;