2N/A/*
2N/A * CDDL HEADER START
2N/A *
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 * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
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 *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1994-1997, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include "quad.h"
2N/A
2N/A#ifdef __sparcv9
2N/A#define _Q_feq _Qp_feq
2N/A#define _Q_fne _Qp_fne
2N/A#define _Q_flt _Qp_flt
2N/A#define _Q_fle _Qp_fle
2N/A#define _Q_fgt _Qp_fgt
2N/A#define _Q_fge _Qp_fge
2N/A#endif
2N/A
2N/A/*
2N/A * _Q_feq(x, y) returns nonzero if *x == *y and zero otherwise.
2N/A * If either *x or *y is a signaling NaN, the invalid operation
2N/A * exception is raised.
2N/A */
2N/Aint
2N/A_Q_feq(const union longdouble *x, const union longdouble *y)
2N/A{
2N/A unsigned int fsr;
2N/A
2N/A if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
2N/A if ((QUAD_ISNAN(*x) && !(x->l.msw & 0x8000)) ||
2N/A (QUAD_ISNAN(*y) && !(y->l.msw & 0x8000))) {
2N/A /* snan, signal invalid */
2N/A __quad_getfsrp(&fsr);
2N/A if (fsr & FSR_NVM) {
2N/A __quad_fcmpq(x, y, &fsr);
2N/A return (((fsr >> 10) & 3) == fcc_equal);
2N/A } else {
2N/A fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
2N/A __quad_setfsrp(&fsr);
2N/A }
2N/A }
2N/A return (0);
2N/A }
2N/A if (QUAD_ISZERO(*x) && QUAD_ISZERO(*y))
2N/A return (1);
2N/A return ((x->l.msw ^ y->l.msw | x->l.frac2 ^ y->l.frac2 |
2N/A x->l.frac3 ^ y->l.frac3 | x->l.frac4 ^ y->l.frac4) == 0);
2N/A}
2N/A
2N/A/*
2N/A * _Q_fne(x, y) returns nonzero if *x != *y and zero otherwise.
2N/A * If either *x or *y is a signaling NaN, the invalid operation
2N/A * exception is raised.
2N/A */
2N/Aint
2N/A_Q_fne(const union longdouble *x, const union longdouble *y)
2N/A{
2N/A unsigned int fsr;
2N/A
2N/A if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
2N/A if ((QUAD_ISNAN(*x) && !(x->l.msw & 0x8000)) ||
2N/A (QUAD_ISNAN(*y) && !(y->l.msw & 0x8000))) {
2N/A /* snan, signal invalid */
2N/A __quad_getfsrp(&fsr);
2N/A if (fsr & FSR_NVM) {
2N/A __quad_fcmpq(x, y, &fsr);
2N/A return (((fsr >> 10) & 3) != fcc_equal);
2N/A } else {
2N/A fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
2N/A __quad_setfsrp(&fsr);
2N/A }
2N/A }
2N/A return (1); /* x != y is TRUE if x or y is NaN */
2N/A }
2N/A if (QUAD_ISZERO(*x) && QUAD_ISZERO(*y))
2N/A return (0);
2N/A return ((x->l.msw ^ y->l.msw | x->l.frac2 ^ y->l.frac2 |
2N/A x->l.frac3 ^ y->l.frac3 | x->l.frac4 ^ y->l.frac4) != 0);
2N/A}
2N/A
2N/A/*
2N/A * _Q_flt(x, y) returns nonzero if *x < *y and zero otherwise. If
2N/A * either *x or *y is NaN, the invalid operation exception is raised.
2N/A */
2N/Aint
2N/A_Q_flt(const union longdouble *x, const union longdouble *y)
2N/A{
2N/A unsigned int xm, ym, fsr;
2N/A
2N/A if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
2N/A /* nan, signal invalid */
2N/A __quad_getfsrp(&fsr);
2N/A if (fsr & FSR_NVM) {
2N/A __quad_fcmpeq(x, y, &fsr);
2N/A return (((fsr >> 10) & 3) == fcc_less);
2N/A } else {
2N/A fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
2N/A __quad_setfsrp(&fsr);
2N/A }
2N/A return (0);
2N/A }
2N/A
2N/A /* ignore sign of zero */
2N/A xm = x->l.msw;
2N/A if (QUAD_ISZERO(*x))
2N/A xm &= 0x7fffffff;
2N/A ym = y->l.msw;
2N/A if (QUAD_ISZERO(*y))
2N/A ym &= 0x7fffffff;
2N/A
2N/A if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
2N/A return ((ym & 0x80000000) == 0);
2N/A
2N/A if (xm & 0x80000000) {
2N/A return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
2N/A x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
2N/A x->l.frac3 == y->l.frac3 && x->l.frac4 > y->l.frac4)));
2N/A }
2N/A return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
2N/A x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
2N/A x->l.frac3 == y->l.frac3 && x->l.frac4 < y->l.frac4)));
2N/A}
2N/A
2N/A/*
2N/A * _Q_fle(x, y) returns nonzero if *x <= *y and zero otherwise. If
2N/A * either *x or *y is NaN, the invalid operation exception is raised.
2N/A */
2N/Aint
2N/A_Q_fle(const union longdouble *x, const union longdouble *y)
2N/A{
2N/A unsigned int xm, ym, fsr;
2N/A
2N/A if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
2N/A /* nan, signal invalid */
2N/A __quad_getfsrp(&fsr);
2N/A if (fsr & FSR_NVM) {
2N/A __quad_fcmpeq(x, y, &fsr);
2N/A fsr = (fsr >> 10) & 3;
2N/A return (fsr == fcc_less || fsr == fcc_equal);
2N/A } else {
2N/A fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
2N/A __quad_setfsrp(&fsr);
2N/A }
2N/A return (0);
2N/A }
2N/A
2N/A /* ignore sign of zero */
2N/A xm = x->l.msw;
2N/A if (QUAD_ISZERO(*x))
2N/A xm &= 0x7fffffff;
2N/A ym = y->l.msw;
2N/A if (QUAD_ISZERO(*y))
2N/A ym &= 0x7fffffff;
2N/A
2N/A if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
2N/A return ((ym & 0x80000000) == 0);
2N/A
2N/A if (xm & 0x80000000) {
2N/A return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
2N/A x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
2N/A x->l.frac3 == y->l.frac3 && x->l.frac4 >= y->l.frac4)));
2N/A }
2N/A return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
2N/A x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
2N/A x->l.frac3 == y->l.frac3 && x->l.frac4 <= y->l.frac4)));
2N/A}
2N/A
2N/A/*
2N/A * _Q_fgt(x, y) returns nonzero if *x > *y and zero otherwise. If
2N/A * either *x or *y is NaN, the invalid operation exception is raised.
2N/A */
2N/Aint
2N/A_Q_fgt(const union longdouble *x, const union longdouble *y)
2N/A{
2N/A unsigned int xm, ym, fsr;
2N/A
2N/A if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
2N/A /* nan, signal invalid */
2N/A __quad_getfsrp(&fsr);
2N/A if (fsr & FSR_NVM) {
2N/A __quad_fcmpeq(x, y, &fsr);
2N/A return (((fsr >> 10) & 3) == fcc_greater);
2N/A } else {
2N/A fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
2N/A __quad_setfsrp(&fsr);
2N/A }
2N/A return (0);
2N/A }
2N/A
2N/A /* ignore sign of zero */
2N/A xm = x->l.msw;
2N/A if (QUAD_ISZERO(*x))
2N/A xm &= 0x7fffffff;
2N/A ym = y->l.msw;
2N/A if (QUAD_ISZERO(*y))
2N/A ym &= 0x7fffffff;
2N/A
2N/A if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
2N/A return ((ym & 0x80000000) != 0);
2N/A
2N/A if (xm & 0x80000000) {
2N/A return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
2N/A x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
2N/A x->l.frac3 == y->l.frac3 && x->l.frac4 < y->l.frac4)));
2N/A }
2N/A return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
2N/A x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
2N/A x->l.frac3 == y->l.frac3 && x->l.frac4 > y->l.frac4)));
2N/A}
2N/A
2N/A/*
2N/A * _Q_fge(x, y) returns nonzero if *x >= *y and zero otherwise. If
2N/A * either *x or *y is NaN, the invalid operation exception is raised.
2N/A */
2N/Aint
2N/A_Q_fge(const union longdouble *x, const union longdouble *y)
2N/A{
2N/A unsigned int xm, ym, fsr;
2N/A
2N/A if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
2N/A /* nan, signal invalid */
2N/A __quad_getfsrp(&fsr);
2N/A if (fsr & FSR_NVM) {
2N/A __quad_fcmpeq(x, y, &fsr);
2N/A fsr = (fsr >> 10) & 3;
2N/A return (fsr == fcc_greater || fsr == fcc_equal);
2N/A } else {
2N/A fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
2N/A __quad_setfsrp(&fsr);
2N/A }
2N/A return (0);
2N/A }
2N/A
2N/A /* ignore sign of zero */
2N/A xm = x->l.msw;
2N/A if (QUAD_ISZERO(*x))
2N/A xm &= 0x7fffffff;
2N/A ym = y->l.msw;
2N/A if (QUAD_ISZERO(*y))
2N/A ym &= 0x7fffffff;
2N/A
2N/A if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
2N/A return ((ym & 0x80000000) != 0);
2N/A
2N/A if (xm & 0x80000000) {
2N/A return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
2N/A x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
2N/A x->l.frac3 == y->l.frac3 && x->l.frac4 <= y->l.frac4)));
2N/A }
2N/A return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
2N/A x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
2N/A x->l.frac3 == y->l.frac3 && x->l.frac4 >= y->l.frac4)));
2N/A}