/* IEEE754 floating point arithmetic1* double precision: common utilities2*/3/*4* MIPS floating point support5* Copyright (C) 1994-2000 Algorithmics Ltd.6*7* ########################################################################8*9* This program is free software; you can distribute it and/or modify it10* under the terms of the GNU General Public License (Version 2) as11* published by the Free Software Foundation.12*13* This program is distributed in the hope it will be useful, but WITHOUT14* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or15* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License16* for more details.17*18* You should have received a copy of the GNU General Public License along19* with this program; if not, write to the Free Software Foundation, Inc.,20* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.21*22* ########################################################################23*/242526#include "ieee754dp.h"2728int ieee754dp_finite(ieee754dp x)29{30return DPBEXP(x) != DP_EMAX + 1 + DP_EBIAS;31}3233ieee754dp ieee754dp_copysign(ieee754dp x, ieee754dp y)34{35CLEARCX;36DPSIGN(x) = DPSIGN(y);37return x;38}394041ieee754dp ieee754dp_neg(ieee754dp x)42{43COMPXDP;4445EXPLODEXDP;46CLEARCX;47FLUSHXDP;4849/*50* Invert the sign ALWAYS to prevent an endless recursion on51* pow() in libc.52*/53/* quick fix up */54DPSIGN(x) ^= 1;5556if (xc == IEEE754_CLASS_SNAN) {57ieee754dp y = ieee754dp_indef();58SETCX(IEEE754_INVALID_OPERATION);59DPSIGN(y) = DPSIGN(x);60return ieee754dp_nanxcpt(y, "neg");61}6263return x;64}656667ieee754dp ieee754dp_abs(ieee754dp x)68{69COMPXDP;7071EXPLODEXDP;72CLEARCX;73FLUSHXDP;7475/* Clear sign ALWAYS, irrespective of NaN */76DPSIGN(x) = 0;7778if (xc == IEEE754_CLASS_SNAN) {79SETCX(IEEE754_INVALID_OPERATION);80return ieee754dp_nanxcpt(ieee754dp_indef(), "abs");81}8283return x;84}858687