github.com/guyezi/gofrontend@v0.0.0-20200228202240-7a62a49e62c0/libgo/runtime/go-cdiv.c (about)

     1  /* go-cdiv.c -- complex division routines
     2  
     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.  */
     6  
     7  #include <complex.h>
     8  #include <math.h>
     9  
    10  /* Calls to these functions are generated by the Go frontend for
    11     division of complex64 or complex128.  We use these because Go's
    12     complex division expects slightly different results from the GCC
    13     default.  When dividing NaN+1.0i / 0+0i, Go expects NaN+NaNi but
    14     GCC generates NaN+Infi.  NaN+Infi seems wrong seems the rules of
    15     C99 Annex G specify that if either side of a complex number is Inf,
    16     the the whole number is Inf, but an operation involving NaN ought
    17     to result in NaN, not Inf.  */
    18  
    19  complex float
    20  __go_complex64_div (complex float a, complex float b)
    21  {
    22    if (__builtin_expect (b == 0, 0))
    23      {
    24        if (!isinf (crealf (a))
    25  	  && !isinf (cimagf (a))
    26  	  && (isnan (crealf (a)) || isnan (cimagf (a))))
    27  	{
    28  	  /* Pass "1" to nanf to match math/bits.go.  */
    29  	  return nanf("1") + nanf("1")*I;
    30  	}
    31      }
    32    return a / b;
    33  }
    34  
    35  complex double
    36  __go_complex128_div (complex double a, complex double b)
    37  {
    38    if (__builtin_expect (b == 0, 0))
    39      {
    40        if (!isinf (creal (a))
    41  	  && !isinf (cimag (a))
    42  	  && (isnan (creal (a)) || isnan (cimag (a))))
    43  	{
    44  	  /* Pass "1" to nan to match math/bits.go.  */
    45  	  return nan("1") + nan("1")*I;
    46  	}
    47      }
    48    return a / b;
    49  }