// 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 math// Coefficients _sin[] and _cos[] are found in pkg/math/sin.go.// Sincos returns Sin(x), Cos(x).//// Special cases are://// Sincos(±0) = ±0, 1// Sincos(±Inf) = NaN, NaN// Sincos(NaN) = NaN, NaNfunc ( float64) (, float64) {const ( = 7.85398125648498535156e-1// 0x3fe921fb40000000, Pi/4 split into three parts = 3.77489470793079817668e-8// 0x3e64442d00000000, = 2.69515142907905952645e-15// 0x3ce8469898cc5170, )// special casesswitch {case == 0:return , 1// return ±0.0, 1.0caseIsNaN() || IsInf(, 0):returnNaN(), NaN() }// make argument positive , := false, falseif < 0 { = - = true }varuint64var , float64if >= reduceThreshold { , = trigReduce() } else { = uint64( * (4 / Pi)) // integer part of x/(Pi/4), as integer for tests on the phase angle = float64() // integer part of x/(Pi/4), as floatif &1 == 1 { // map zeros to origin ++ ++ } &= 7// octant modulo 2Pi radians (360 degrees) = (( - *) - *) - * // Extended precision modular arithmetic }if > 3 { // reflect in x axis -= 4 , = !, ! }if > 1 { = ! } := * = 1.0 - 0.5* + **((((((_cos[0]*)+_cos[1])*+_cos[2])*+_cos[3])*+_cos[4])*+_cos[5]) = + **((((((_sin[0]*)+_sin[1])*+_sin[2])*+_sin[3])*+_sin[4])*+_sin[5])if == 1 || == 2 { , = , }if { = - }if { = - }return}
The pages are generated with Goldsv0.7.3. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.