File: /usr/src/linux/arch/mips64/math-emu/dp_tint.c
1 /* IEEE754 floating point arithmetic
2 * double precision: common utilities
3 */
4 /*
5 * MIPS floating point support
6 * Copyright (C) 1994-2000 Algorithmics Ltd. All rights reserved.
7 * http://www.algor.co.uk
8 *
9 * ########################################################################
10 *
11 * This program is free software; you can distribute it and/or modify it
12 * under the terms of the GNU General Public License (Version 2) as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 *
24 * ########################################################################
25 */
26
27
28 #include <linux/kernel.h>
29 #include "ieee754dp.h"
30
31 int ieee754dp_tint(ieee754dp x)
32 {
33 COMPXDP;
34
35 CLEARCX;
36
37 EXPLODEXDP;
38
39 switch (xc) {
40 case IEEE754_CLASS_SNAN:
41 case IEEE754_CLASS_QNAN:
42 SETCX(IEEE754_INVALID_OPERATION);
43 return ieee754si_xcpt(ieee754si_indef(), "fixdp", x);
44 case IEEE754_CLASS_INF:
45 SETCX(IEEE754_OVERFLOW);
46 return ieee754si_xcpt(ieee754si_indef(), "fixdp", x);
47 case IEEE754_CLASS_ZERO:
48 return 0;
49 case IEEE754_CLASS_DNORM: /* much to small */
50 SETCX(IEEE754_UNDERFLOW);
51 return ieee754si_xcpt(0, "fixdp", x);
52 case IEEE754_CLASS_NORM:
53 break;
54 }
55 if (xe >= 31) {
56 SETCX(IEEE754_OVERFLOW);
57 return ieee754si_xcpt(ieee754si_indef(), "fix", x);
58 }
59 if (xe < 0) {
60 SETCX(IEEE754_UNDERFLOW);
61 return ieee754si_xcpt(0, "fix", x);
62 }
63 /* oh gawd */
64 if (xe > DP_MBITS) {
65 xm <<= xe - DP_MBITS;
66 } else if (xe < DP_MBITS) {
67 /* XXX no rounding
68 */
69 xm >>= DP_MBITS - xe;
70 }
71 if (xs)
72 return -xm;
73 else
74 return xm;
75 }
76
77
78 unsigned int ieee754dp_tuns(ieee754dp x)
79 {
80 ieee754dp hb = ieee754dp_1e31();
81
82 /* what if x < 0 ?? */
83 if (ieee754dp_lt(x, hb))
84 return (unsigned) ieee754dp_tint(x);
85
86 return (unsigned) ieee754dp_tint(ieee754dp_sub(x, hb)) |
87 ((unsigned) 1 << 31);
88 }
89