1 /* 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 * 6 * @(#)z_div.c 5.3 01/15/91 7 */ 8 9 #include "complex" 10 #include <stdio.h> 11 #include <errno.h> 12 #ifdef tahoe 13 #include <tahoe/math/FP.h> 14 #endif 15 16 z_div(c, a, b) 17 dcomplex *a, *b, *c; 18 { 19 double ratio, den; 20 double abr, abi; 21 22 #ifndef tahoe 23 if( (abr = b->dreal) < 0.) 24 abr = - abr; 25 if( (abi = b->dimag) < 0.) 26 abi = - abi; 27 #else tahoe 28 if( (abr = b->dreal) < 0.) 29 *((long int *)&abr) ^= SIGN_BIT; 30 if( (abi = b->dimag) < 0.) 31 *((long int *)&abi) ^= SIGN_BIT; 32 #endif tahoe 33 if( abr <= abi ) 34 { 35 if(abi == 0) { 36 fprintf( stderr, "Double complex division by zero\n" ); 37 f77_abort(EDOM); 38 } 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 45 else 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 } 54