/* 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"2728/* modf function is always exact for a finite number29*/30ieee754dp ieee754dp_modf(ieee754dp x, ieee754dp *ip)31{32COMPXDP;3334CLEARCX;3536EXPLODEXDP;3738switch (xc) {39case IEEE754_CLASS_SNAN:40case IEEE754_CLASS_QNAN:41case IEEE754_CLASS_INF:42case IEEE754_CLASS_ZERO:43*ip = x;44return x;45case IEEE754_CLASS_DNORM:46/* far to small */47*ip = ieee754dp_zero(xs);48return x;49case IEEE754_CLASS_NORM:50break;51}52if (xe < 0) {53*ip = ieee754dp_zero(xs);54return x;55}56if (xe >= DP_MBITS) {57*ip = x;58return ieee754dp_zero(xs);59}60/* generate ipart mantissa by clearing bottom bits61*/62*ip = builddp(xs, xe + DP_EBIAS,63((xm >> (DP_MBITS - xe)) << (DP_MBITS - xe)) &64~DP_HIDDEN_BIT);6566/* generate fpart mantissa by clearing top bits67* and normalizing (must be able to normalize)68*/69xm = (xm << (64 - (DP_MBITS - xe))) >> (64 - (DP_MBITS - xe));70if (xm == 0)71return ieee754dp_zero(xs);7273while ((xm >> DP_MBITS) == 0) {74xm <<= 1;75xe--;76}77return builddp(xs, xe + DP_EBIAS, xm & ~DP_HIDDEN_BIT);78}798081