diff options
author | Ken Thompson <ken@golang.org> | 2010-03-09 12:49:24 -0800 |
---|---|---|
committer | Ken Thompson <ken@golang.org> | 2010-03-09 12:49:24 -0800 |
commit | b129670ca135bd6be7b4afcadeb0bcec0675789e (patch) | |
tree | 4e5f22c966654acdf90e8c3a69c56b0394bcfe65 /src/pkg/runtime | |
parent | de5d91c7acfd1deca9bf01eb944b2704b83b8899 (diff) | |
download | golang-b129670ca135bd6be7b4afcadeb0bcec0675789e.tar.gz |
identical complex implementation
for 6g and 8g. can also be used
for 5g. 5g is still a stub.
R=rsc
CC=golang-dev
http://codereview.appspot.com/362041
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r-- | src/pkg/runtime/Makefile | 1 | ||||
-rw-r--r-- | src/pkg/runtime/complex.c | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/pkg/runtime/Makefile b/src/pkg/runtime/Makefile index 767472063..103515c13 100644 --- a/src/pkg/runtime/Makefile +++ b/src/pkg/runtime/Makefile @@ -48,6 +48,7 @@ OFILES=\ chan.$O\ closure.$O\ float.$O\ + complex.$O\ hashmap.$O\ iface.$O\ malloc.$O\ diff --git a/src/pkg/runtime/complex.c b/src/pkg/runtime/complex.c new file mode 100644 index 000000000..72c65467d --- /dev/null +++ b/src/pkg/runtime/complex.c @@ -0,0 +1,36 @@ +// 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. + +#include "runtime.h" + +// complex128div(num, den complex128) (quo complex128) +void +·complex128div(float64 numreal, float64 numimag, + float64 denreal, float64 denimag, + float64 quoreal, float64 quoimag) +{ + float64 a, b, ratio, denom; + + a = denreal; + if(a < 0) + a = -a; + b = denimag; + if(b < 0) + b = -b; + if(a <= b) { + if(b == 0) + throw("complex divide"); + ratio = denreal/denimag; + denom = denreal*ratio + denimag; + quoreal = (numreal*ratio + numimag) / denom; + quoimag = (numimag*ratio - numreal) / denom; + } else { + ratio = denimag/denreal; + denom = denimag*ratio + denreal; + quoreal = (numimag*ratio + numreal) / denom; + quoimag = (numimag - numreal*ratio) / denom; + } + FLUSH(&quoreal); + FLUSH(&quoimag); +} |