examples: add most docstrings
This commit is contained in:
@@ -7,19 +7,22 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
TEXT("Real", "func(x complex128) float64")
|
||||
r := Load(Param("x").Real(), Xv())
|
||||
TEXT("Real", "func(z complex128) float64")
|
||||
Doc("Real returns the real part of z.")
|
||||
r := Load(Param("z").Real(), Xv())
|
||||
Store(r, ReturnIndex(0))
|
||||
RET()
|
||||
|
||||
TEXT("Imag", "func(x complex128) float64")
|
||||
i := Load(Param("x").Imag(), Xv())
|
||||
TEXT("Imag", "func(z complex128) float64")
|
||||
Doc("Imag returns the imaginary part of z.")
|
||||
i := Load(Param("z").Imag(), Xv())
|
||||
Store(i, ReturnIndex(0))
|
||||
RET()
|
||||
|
||||
TEXT("Norm", "func(x complex128) float64")
|
||||
r = Load(Param("x").Real(), Xv())
|
||||
i = Load(Param("x").Imag(), Xv())
|
||||
TEXT("Norm", "func(z complex128) float64")
|
||||
Doc("Norm returns the complex norm of z.")
|
||||
r = Load(Param("z").Real(), Xv())
|
||||
i = Load(Param("z").Imag(), Xv())
|
||||
MULSD(r, r)
|
||||
MULSD(i, i)
|
||||
ADDSD(i, r)
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
// func Real(x complex128) float64
|
||||
// func Real(z complex128) float64
|
||||
TEXT ·Real(SB), 0, $0-24
|
||||
MOVSD x_real(FP), X0
|
||||
MOVSD z_real(FP), X0
|
||||
MOVSD X0, ret+16(FP)
|
||||
RET
|
||||
|
||||
// func Imag(x complex128) float64
|
||||
// func Imag(z complex128) float64
|
||||
TEXT ·Imag(SB), 0, $0-24
|
||||
MOVSD x_imag+8(FP), X0
|
||||
MOVSD z_imag+8(FP), X0
|
||||
MOVSD X0, ret+16(FP)
|
||||
RET
|
||||
|
||||
// func Norm(x complex128) float64
|
||||
// func Norm(z complex128) float64
|
||||
TEXT ·Norm(SB), 0, $0-24
|
||||
MOVSD x_real(FP), X0
|
||||
MOVSD x_imag+8(FP), X1
|
||||
MOVSD z_real(FP), X0
|
||||
MOVSD z_imag+8(FP), X1
|
||||
MULSD X0, X0
|
||||
MULSD X1, X1
|
||||
ADDSD X1, X0
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
//go:generate go run asm.go -out complex.s -stubs stub.go
|
||||
|
||||
func TestReal(t *testing.T) {
|
||||
expect := func(x complex128) float64 {
|
||||
return real(x)
|
||||
expect := func(z complex128) float64 {
|
||||
return real(z)
|
||||
}
|
||||
if err := quick.CheckEqual(Real, expect, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -18,8 +18,8 @@ func TestReal(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestImag(t *testing.T) {
|
||||
expect := func(x complex128) float64 {
|
||||
return imag(x)
|
||||
expect := func(z complex128) float64 {
|
||||
return imag(z)
|
||||
}
|
||||
if err := quick.CheckEqual(Imag, expect, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -27,8 +27,8 @@ func TestImag(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNorm(t *testing.T) {
|
||||
expect := func(x complex128) float64 {
|
||||
return math.Sqrt(real(x)*real(x) + imag(x)*imag(x))
|
||||
expect := func(z complex128) float64 {
|
||||
return math.Sqrt(real(z)*real(z) + imag(z)*imag(z))
|
||||
}
|
||||
if err := quick.CheckEqual(Norm, expect, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
|
||||
package complex
|
||||
|
||||
func Real(x complex128) float64
|
||||
// Real returns the real part of z.
|
||||
func Real(z complex128) float64
|
||||
|
||||
func Imag(x complex128) float64
|
||||
// Imag returns the imaginary part of z.
|
||||
func Imag(z complex128) float64
|
||||
|
||||
func Norm(x complex128) float64
|
||||
// Norm returns the complex norm of z.
|
||||
func Norm(z complex128) float64
|
||||
|
||||
Reference in New Issue
Block a user