stdio.h defines BUFSIZ
[unix-history] / usr / src / usr.bin / f77 / libF77 / z_div.c
CommitLineData
fdcfbf89 1/*
3337a9c2
RE
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 *
a8b283ea 6 * @(#)z_div.c 5.3 %G%
fdcfbf89
DW
7 */
8
9#include "complex"
50fd198f
DL
10#include <stdio.h>
11#include <errno.h>
0ab3343e 12#ifdef tahoe
a8b283ea
KB
13#include <tahoe/math/FP.h>
14#endif
fdcfbf89
DW
15
16z_div(c, a, b)
17dcomplex *a, *b, *c;
18{
19double ratio, den;
20double abr, abi;
21
0ab3343e 22#ifndef tahoe
fdcfbf89
DW
23if( (abr = b->dreal) < 0.)
24 abr = - abr;
25if( (abi = b->dimag) < 0.)
26 abi = - abi;
0ab3343e
KM
27#else tahoe
28if( (abr = b->dreal) < 0.)
29 *((long int *)&abr) ^= SIGN_BIT;
30if( (abi = b->dimag) < 0.)
31 *((long int *)&abi) ^= SIGN_BIT;
32#endif tahoe
fdcfbf89
DW
33if( abr <= abi )
34 {
50fd198f
DL
35 if(abi == 0) {
36 fprintf( stderr, "Double complex division by zero\n" );
37 f77_abort(EDOM);
38 }
fdcfbf89
DW
39 ratio = b->dreal / b->dimag ;
40 den = b->dimag * (1 + ratio*ratio);
41 c->dreal = (a->dreal*ratio + a->dimag) / den;
42 c->dimag = (a->dimag*ratio - a->dreal) / den;
43 }
44
45else
46 {
47 ratio = b->dimag / b->dreal ;
48 den = b->dreal * (1 + ratio*ratio);
49 c->dreal = (a->dreal + a->dimag*ratio) / den;
50 c->dimag = (a->dimag - a->dreal*ratio) / den;
51 }
52
53}