/* 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"2728ieee754dp ieee754dp_fint(int x)29{30u64 xm;31int xe;32int xs;3334CLEARCX;3536if (x == 0)37return ieee754dp_zero(0);38if (x == 1 || x == -1)39return ieee754dp_one(x < 0);40if (x == 10 || x == -10)41return ieee754dp_ten(x < 0);4243xs = (x < 0);44if (xs) {45if (x == (1 << 31))46xm = ((unsigned) 1 << 31); /* max neg can't be safely negated */47else48xm = -x;49} else {50xm = x;51}5253#if 154/* normalize - result can never be inexact or overflow */55xe = DP_MBITS;56while ((xm >> DP_MBITS) == 0) {57xm <<= 1;58xe--;59}60return builddp(xs, xe + DP_EBIAS, xm & ~DP_HIDDEN_BIT);61#else62/* normalize */63xe = DP_MBITS + 3;64while ((xm >> (DP_MBITS + 3)) == 0) {65xm <<= 1;66xe--;67}68DPNORMRET1(xs, xe, xm, "fint", x);69#endif70}7172ieee754dp ieee754dp_funs(unsigned int u)73{74if ((int) u < 0)75return ieee754dp_add(ieee754dp_1e31(),76ieee754dp_fint(u & ~(1 << 31)));77return ieee754dp_fint(u);78}798081