Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* IEEE754 floating point arithmetic |
2 | * single precision | |
3 | */ | |
4 | /* | |
5 | * MIPS floating point support | |
6 | * Copyright (C) 1994-2000 Algorithmics Ltd. | |
1da177e4 LT |
7 | * |
8 | * ######################################################################## | |
9 | * | |
10 | * This program is free software; you can distribute it and/or modify it | |
11 | * under the terms of the GNU General Public License (Version 2) as | |
12 | * published by the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope it will be useful, but WITHOUT | |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 | * for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write to the Free Software Foundation, Inc., | |
21 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
22 | * | |
23 | * ######################################################################## | |
24 | */ | |
25 | ||
26 | ||
27 | #include "ieee754sp.h" | |
28 | ||
2209bcb1 | 29 | union ieee754sp ieee754sp_neg(union ieee754sp x) |
1da177e4 LT |
30 | { |
31 | COMPXSP; | |
32 | ||
33 | EXPLODEXSP; | |
9e8bad1f | 34 | ieee754_clearcx(); |
1da177e4 LT |
35 | FLUSHXSP; |
36 | ||
c5033d78 AN |
37 | /* |
38 | * Invert the sign ALWAYS to prevent an endless recursion on | |
39 | * pow() in libc. | |
40 | */ | |
41 | /* quick fix up */ | |
42 | SPSIGN(x) ^= 1; | |
43 | ||
1da177e4 | 44 | if (xc == IEEE754_CLASS_SNAN) { |
2209bcb1 | 45 | union ieee754sp y = ieee754sp_indef(); |
9e8bad1f | 46 | ieee754_setcx(IEEE754_INVALID_OPERATION); |
c5033d78 | 47 | SPSIGN(y) = SPSIGN(x); |
90efba36 | 48 | return ieee754sp_nanxcpt(y); |
1da177e4 LT |
49 | } |
50 | ||
1da177e4 LT |
51 | return x; |
52 | } | |
53 | ||
54 | ||
2209bcb1 | 55 | union ieee754sp ieee754sp_abs(union ieee754sp x) |
1da177e4 LT |
56 | { |
57 | COMPXSP; | |
58 | ||
59 | EXPLODEXSP; | |
9e8bad1f | 60 | ieee754_clearcx(); |
1da177e4 LT |
61 | FLUSHXSP; |
62 | ||
cea2be44 NS |
63 | /* Clear sign ALWAYS, irrespective of NaN */ |
64 | SPSIGN(x) = 0; | |
65 | ||
1da177e4 | 66 | if (xc == IEEE754_CLASS_SNAN) { |
9e8bad1f | 67 | ieee754_setcx(IEEE754_INVALID_OPERATION); |
90efba36 | 68 | return ieee754sp_nanxcpt(ieee754sp_indef()); |
1da177e4 LT |
69 | } |
70 | ||
1da177e4 LT |
71 | return x; |
72 | } |