| 1 |
// { dg-do compile } |
| 2 |
// { dg-options "-O3 -g" } |
| 3 |
// { dg-additional-options "-mtune=thunderxt88" { target aarch64*-*-* } } |
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
import "math" |
| 8 |
|
| 9 |
func sinhcosh(x float64) (sh, ch float64) { |
| 10 |
if math.Abs(x) <= 0.5 { |
| 11 |
return math.Sinh(x), math.Cosh(x) |
| 12 |
} |
| 13 |
e := math.Exp(x) |
| 14 |
ei := 0.5 / e |
| 15 |
e *= 0.5 |
| 16 |
return e - ei, e + ei |
| 17 |
} |
| 18 |
|
| 19 |
func Cos(x complex128) complex128 { |
| 20 |
switch re, im := real(x), imag(x); { |
| 21 |
case im == 0 && (math.IsInf(re, 0) || math.IsNaN(re)): |
| 22 |
return complex(math.NaN(), -im*math.Copysign(0, re)) |
| 23 |
case math.IsInf(im, 0): |
| 24 |
switch { |
| 25 |
// case re == 0: |
| 26 |
// return complex(math.Inf(1), -re*math.Copysign(0, im)) |
| 27 |
case math.IsInf(re, 0) || math.IsNaN(re): |
| 28 |
return complex(math.Inf(1), math.NaN()) |
| 29 |
} |
| 30 |
// case re == 0 && math.IsNaN(im): |
| 31 |
// return complex(math.NaN(), 0) |
| 32 |
} |
| 33 |
s, c := math.Sincos(real(x)) |
| 34 |
sh, ch := sinhcosh(imag(x)) |
| 35 |
return complex(c*ch, -s*sh) |
| 36 |
} |
| 37 |
|
| 38 |
func main() { |
| 39 |
Cos(complex(2.5, 3.5)) |
| 40 |
} |