github.com/tcnksm/go@v0.0.0-20141208075154-439b32936367/misc/cgo/test/issue8694.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package cgotest 6 7 /* 8 #include <complex.h> 9 10 complex float complexFloatSquared(complex float a) { return a*a; } 11 complex double complexDoubleSquared(complex double a) { return a*a; } 12 */ 13 import "C" 14 15 import "testing" 16 17 func test8694(t *testing.T) { 18 // Really just testing that this compiles, but check answer anyway. 19 x := complex64(2 + 3i) 20 x2 := x * x 21 cx2 := C.complexFloatSquared(x) 22 if cx2 != x2 { 23 t.Errorf("C.complexFloatSquared(%v) = %v, want %v", x, cx2, x2) 24 } 25 26 y := complex128(2 + 3i) 27 y2 := y * y 28 cy2 := C.complexDoubleSquared(y) 29 if cy2 != y2 { 30 t.Errorf("C.complexDoubleSquared(%v) = %v, want %v", y, cy2, y2) 31 } 32 }