// Copyright 2009 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 math

// Ldexp is the inverse of [Frexp].
// It returns frac × 2**exp.
//
// Special cases are:
//
//	Ldexp(±0, exp) = ±0
//	Ldexp(±Inf, exp) = ±Inf
//	Ldexp(NaN, exp) = NaN
func ( float64,  int) float64 {
	if haveArchLdexp {
		return archLdexp(, )
	}
	return ldexp(, )
}

func ldexp( float64,  int) float64 {
	// special cases
	switch {
	case  == 0:
		return  // correctly return -0
	case IsInf(, 0) || IsNaN():
		return 
	}
	,  := normalize()
	 += 
	 := Float64bits()
	 += int(>>shift)&mask - bias
	if  < -1075 {
		return Copysign(0, ) // underflow
	}
	if  > 1023 { // overflow
		if  < 0 {
			return Inf(-1)
		}
		return Inf(1)
	}
	var  float64 = 1
	if  < -1022 { // denormal
		 += 53
		 = 1.0 / (1 << 53) // 2**-53
	}
	 &^= mask << shift
	 |= uint64(+bias) << shift
	return  * Float64frombits()
}