2014-09-21 17:33:12 +00:00
|
|
|
/* go-cdiv.c -- complex division routines
|
|
|
|
|
|
|
|
Copyright 2013 The Go Authors. All rights reserved.
|
|
|
|
Use of this source code is governed by a BSD-style
|
|
|
|
license that can be found in the LICENSE file. */
|
|
|
|
|
2015-08-28 15:33:40 +00:00
|
|
|
#include <complex.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2014-09-21 17:33:12 +00:00
|
|
|
/* Calls to these functions are generated by the Go frontend for
|
|
|
|
division of complex64 or complex128. We use these because Go's
|
|
|
|
complex division expects slightly different results from the GCC
|
|
|
|
default. When dividing NaN+1.0i / 0+0i, Go expects NaN+NaNi but
|
|
|
|
GCC generates NaN+Infi. NaN+Infi seems wrong seems the rules of
|
|
|
|
C99 Annex G specify that if either side of a complex number is Inf,
|
|
|
|
the the whole number is Inf, but an operation involving NaN ought
|
|
|
|
to result in NaN, not Inf. */
|
|
|
|
|
2015-08-28 15:33:40 +00:00
|
|
|
complex float
|
|
|
|
__go_complex64_div (complex float a, complex float b)
|
2014-09-21 17:33:12 +00:00
|
|
|
{
|
2015-08-28 15:33:40 +00:00
|
|
|
if (__builtin_expect (b == 0, 0))
|
2014-09-21 17:33:12 +00:00
|
|
|
{
|
2015-08-28 15:33:40 +00:00
|
|
|
if (!isinf (crealf (a))
|
|
|
|
&& !isinf (cimagf (a))
|
|
|
|
&& (isnan (crealf (a)) || isnan (cimagf (a))))
|
2014-09-21 17:33:12 +00:00
|
|
|
{
|
|
|
|
/* Pass "1" to nanf to match math/bits.go. */
|
2015-08-28 15:33:40 +00:00
|
|
|
return nanf("1") + nanf("1")*I;
|
2014-09-21 17:33:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return a / b;
|
|
|
|
}
|
|
|
|
|
2015-08-28 15:33:40 +00:00
|
|
|
complex double
|
|
|
|
__go_complex128_div (complex double a, complex double b)
|
2014-09-21 17:33:12 +00:00
|
|
|
{
|
2015-08-28 15:33:40 +00:00
|
|
|
if (__builtin_expect (b == 0, 0))
|
2014-09-21 17:33:12 +00:00
|
|
|
{
|
2015-08-28 15:33:40 +00:00
|
|
|
if (!isinf (creal (a))
|
|
|
|
&& !isinf (cimag (a))
|
|
|
|
&& (isnan (creal (a)) || isnan (cimag (a))))
|
2014-09-21 17:33:12 +00:00
|
|
|
{
|
|
|
|
/* Pass "1" to nan to match math/bits.go. */
|
2015-08-28 15:33:40 +00:00
|
|
|
return nan("1") + nan("1")*I;
|
2014-09-21 17:33:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return a / b;
|
|
|
|
}
|