// Copyright 2010 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.

package runtime

// inf2one returns a signed 1 if f is an infinity and a signed 0 otherwise.
// The sign of the result is the sign of f.
func inf2one( float64) float64 {
	 := 0.0
	if isInf() {
		 = 1.0
	}
	return copysign(, )
}

func complex128div( complex128,  complex128) complex128 {
	var ,  float64 // complex(e, f) = n/m

	// Algorithm for robust complex division as described in
	// Robert L. Smith: Algorithm 116: Complex division. Commun. ACM 5(8): 435 (1962).
	if abs(real()) >= abs(imag()) {
		 := imag() / real()
		 := real() + *imag()
		 = (real() + imag()*) / 
		 = (imag() - real()*) / 
	} else {
		 := real() / imag()
		 := imag() + *real()
		 = (real()* + imag()) / 
		 = (imag()* - real()) / 
	}

	if isNaN() && isNaN() {
		// Correct final result to infinities and zeros if applicable.
		// Matches C99: ISO/IEC 9899:1999 - G.5.1  Multiplicative operators.

		,  := real(), imag()
		,  := real(), imag()

		switch {
		case  == 0 && (!isNaN() || !isNaN()):
			 = copysign(inf, ) * 
			 = copysign(inf, ) * 

		case (isInf() || isInf()) && isFinite() && isFinite():
			 = inf2one()
			 = inf2one()
			 = inf * (* + *)
			 = inf * (* - *)

		case (isInf() || isInf()) && isFinite() && isFinite():
			 = inf2one()
			 = inf2one()
			 = 0 * (* + *)
			 = 0 * (* - *)
		}
	}

	return complex(, )
}