2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License, Version 1.0 only 2N/A * (the "License"). You may not use this file except in compliance 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * _F_cplx_mul(z, w) returns z * w with infinities handled according 2N/A * If z and w are both finite, _F_cplx_mul(z, w) delivers the complex 2N/A * product according to the usual formula: let a = Re(z), b = Im(z), 2N/A * c = Re(w), and d = Im(w); then _F_cplx_mul(z, w) delivers x + I * y 2N/A * where x = a * c - b * d and y = a * d + b * c. This implementation 2N/A * uses double precision to form these expressions, so none of the 2N/A * intermediate products can overflow. 2N/A * If one of z or w is infinite and the other is either finite nonzero 2N/A * or infinite, _F_cplx_mul delivers an infinite result. If one factor 2N/A * is infinite and the other is zero, _F_cplx_mul delivers NaN + I * NaN. 2N/A * C99 doesn't specify the latter case. 2N/A * C99 also doesn't specify what should happen if either z or w is a 2N/A * complex NaN (i.e., neither finite nor infinite). This implementation 2N/A * delivers NaN + I * NaN in this case. 2N/A * This implementation can raise spurious invalid operation and inexact 2N/A * exceptions. C99 allows this. 2N/A * Return +1 if x is +Inf, -1 if x is -Inf, and 0 otherwise 2N/A return ((((
xx.i <<
1) -
0xff000000) == 0)? (
1 | (
xx.i >>
31)) : 0);
2N/A * The following is equivalent to 2N/A * a = crealf(z); b = cimagf(z); 2N/A * c = crealf(w); d = cimagf(w); 2N/A a = ((
float *)&z)[0];
2N/A b = ((
float *)&z)[
1];
2N/A c = ((
float *)&w)[0];
2N/A d = ((
float *)&w)[
1];
2N/A x = (
double)a * c - (
double)b * d;
2N/A y = (
double)a * d + (
double)b * c;
2N/A if (x != x && y != y) {
2N/A * Both x and y are NaN, so z and w can't both be finite. 2N/A * If at least one of z or w is a complex NaN, and neither 2N/A * is infinite, then we might as well deliver NaN + I * NaN. 2N/A * So the only cases to check are when one of z or w is 2N/A if (i | j) {
/* z is infinite */ 2N/A /* "factor out" infinity */ 2N/A if (i | j) {
/* w is infinite */ 2N/A /* "factor out" infinity */ 2N/A x =
inf.d * ((
double)a * c - (
double)b * d);
2N/A y =
inf.d * ((
double)a * d + (
double)b * c);
2N/A * The following is equivalent to 2N/A ((
float *)&v)[0] = (
float)x;
2N/A ((
float *)&v)[
1] = (
float)y;