1 /*- 2 * Copyright (c) 1980 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)z_div.c 5.4 (Berkeley) 04/12/91"; 10 #endif /* not lint */ 11 12 #include "complex" 13 #include <stdio.h> 14 #include <errno.h> 15 #ifdef tahoe 16 #include <tahoe/math/FP.h> 17 #endif 18 19 z_div(c, a, b) 20 dcomplex *a, *b, *c; 21 { 22 double ratio, den; 23 double abr, abi; 24 25 #ifndef tahoe 26 if( (abr = b->dreal) < 0.) 27 abr = - abr; 28 if( (abi = b->dimag) < 0.) 29 abi = - abi; 30 #else tahoe 31 if( (abr = b->dreal) < 0.) 32 *((long int *)&abr) ^= SIGN_BIT; 33 if( (abi = b->dimag) < 0.) 34 *((long int *)&abi) ^= SIGN_BIT; 35 #endif tahoe 36 if( abr <= abi ) 37 { 38 if(abi == 0) { 39 fprintf( stderr, "Double complex division by zero\n" ); 40 f77_abort(EDOM); 41 } 42 ratio = b->dreal / b->dimag ; 43 den = b->dimag * (1 + ratio*ratio); 44 c->dreal = (a->dreal*ratio + a->dimag) / den; 45 c->dimag = (a->dimag*ratio - a->dreal) / den; 46 } 47 48 else 49 { 50 ratio = b->dimag / b->dreal ; 51 den = b->dreal * (1 + ratio*ratio); 52 c->dreal = (a->dreal + a->dimag*ratio) / den; 53 c->dimag = (a->dimag - a->dreal*ratio) / den; 54 } 55 56 } 57