mirror of
https://github.com/golang/go
synced 2024-10-04 22:21:22 -06:00
68b4255a96
Prefix all external symbols in runtime by runtime·, to avoid conflicts with possible symbols of the same name in linked-in C libraries. The obvious conflicts are printf, malloc, and free, but hide everything to avoid future pain. The symbols left alone are: ** known to cgo ** _cgo_free _cgo_malloc libcgo_thread_start initcgo ncgocall ** known to linker ** _rt0_$GOARCH _rt0_$GOARCH_$GOOS text etext data end pclntab epclntab symtab esymtab ** known to C compiler ** _divv _modv _div64by32 etc (arch specific) Tested on darwin/386, darwin/amd64, linux/386, linux/amd64. Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386. R=r, PeterGo CC=golang-dev https://golang.org/cl/2899041
61 lines
1.6 KiB
C
61 lines
1.6 KiB
C
// 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"
|
|
|
|
typedef struct Complex128 Complex128;
|
|
|
|
void
|
|
runtime·complex128div(Complex128 n, Complex128 d, Complex128 q)
|
|
{
|
|
int32 ninf, dinf, nnan, dnan;
|
|
float64 a, b, ratio, denom;
|
|
|
|
// Special cases as in C99.
|
|
ninf = runtime·isInf(n.real, 0) || runtime·isInf(n.imag, 0);
|
|
dinf = runtime·isInf(d.real, 0) || runtime·isInf(d.imag, 0);
|
|
|
|
nnan = !ninf && (runtime·isNaN(n.real) || runtime·isNaN(n.imag));
|
|
dnan = !dinf && (runtime·isNaN(d.real) || runtime·isNaN(d.imag));
|
|
|
|
if(nnan || dnan) {
|
|
q.real = runtime·NaN();
|
|
q.imag = runtime·NaN();
|
|
} else if(ninf && !dinf && !dnan) {
|
|
q.real = runtime·Inf(0);
|
|
q.imag = runtime·Inf(0);
|
|
} else if(!ninf && !nnan && dinf) {
|
|
q.real = 0;
|
|
q.imag = 0;
|
|
} else if(d.real == 0 && d.imag == 0) {
|
|
if(n.real == 0 && n.imag == 0) {
|
|
q.real = runtime·NaN();
|
|
q.imag = runtime·NaN();
|
|
} else {
|
|
q.real = runtime·Inf(0);
|
|
q.imag = runtime·Inf(0);
|
|
}
|
|
} else {
|
|
// Standard complex arithmetic, factored to avoid unnecessary overflow.
|
|
a = d.real;
|
|
if(a < 0)
|
|
a = -a;
|
|
b = d.imag;
|
|
if(b < 0)
|
|
b = -b;
|
|
if(a <= b) {
|
|
ratio = d.real/d.imag;
|
|
denom = d.real*ratio + d.imag;
|
|
q.real = (n.real*ratio + n.imag) / denom;
|
|
q.imag = (n.imag*ratio - n.real) / denom;
|
|
} else {
|
|
ratio = d.imag/d.real;
|
|
denom = d.imag*ratio + d.real;
|
|
q.real = (n.imag*ratio + n.real) / denom;
|
|
q.imag = (n.imag - n.real*ratio) / denom;
|
|
}
|
|
}
|
|
FLUSH(&q);
|
|
}
|