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 * On SPARC V8, _Q_cplx_mul(v, z, w) sets *v = *z * *w with infinities 2N/A * handled according to C99. 2N/A * On SPARC V9, _Q_cplx_mul(z, w) returns *z * *w with infinities 2N/A * handled according to C99. 2N/A * If z and w are both finite, _Q_cplx_mul 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 _Q_cplx_mul delivers x + I * y 2N/A * where x = a * c - b * d and y = a * d + b * c. Note that if both 2N/A * ac and bd overflow, then at least one of ad or bc must also over- 2N/A * flow, and vice versa, so that if one component of the product is 2N/A * NaN, the other is infinite. (Such a value is considered infinite 2N/A * according to C99.) 2N/A * If one of z or w is infinite and the other is either finite nonzero 2N/A * or infinite, _Q_cplx_mul delivers an infinite result. If one factor 2N/A * is infinite and the other is zero, _Q_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 underflow, overflow, invalid 2N/A * operation, and inexact 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[0] <<
1) -
0xfffe0000) |
xx.i[
1] |
xx.i[
2] |
xx.i[
3])
2N/A == 0)? (
1 | (
xx.i[0] >>
31)) : 0);
2N/A_Q_cplx_mul(
const long double _Complex *z,
const long double _Complex *w)
2N/A long double _Complex v;
2N/A const long double _Complex *w)
2N/A long double a, b, c, d, x, y;
2N/A * The following is equivalent to 2N/A * a = creall(*z); b = cimagl(*z); 2N/A * c = creall(*w); d = cimagl(*w); 2N/A a = ((
long double *)z)[0];
2N/A b = ((
long double *)z)[
1];
2N/A c = ((
long double *)w)[0];
2N/A d = ((
long double *)w)[
1];
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 ((
long double *)&v)[0] = x;
2N/A ((
long double *)&v)[
1] = y;
2N/A ((
long double *)v)[0] = x;
2N/A ((
long double *)v)[
1] = y;