00001 /* Temporary support for a libc-like fp environment for decimal float. 00002 Copyright (C) 2005 Free Software Foundation, Inc. 00003 00004 This file is part of GCC. 00005 00006 GCC is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2, or (at your option) 00009 any later version. 00010 00011 In addition to the permissions in the GNU General Public License, 00012 the Free Software Foundation gives you unlimited permission to link 00013 the compiled version of this file into combinations with other 00014 programs, and to distribute those combinations without any 00015 restriction coming from the use of this file. (The General Public 00016 License restrictions do apply in other respects; for example, they 00017 cover modification of the file, and distribution when not linked 00018 into a combine executable.) 00019 00020 GCC is distributed in the hope that it will be useful, but WITHOUT 00021 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00022 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 00023 License for more details. 00024 00025 You should have received a copy of the GNU General Public License 00026 along with GCC; see the file COPYING. If not, write to the Free 00027 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 00028 02110-1301, USA. */ 00029 00030 #include "config.h" 00031 #include "decContext.h" 00032 00033 #define FE_DEC_DOWNWARD 0 00034 #define FE_DEC_TONEAREST 1 00035 #define FE_DEC_TONEARESTFROMZERO 2 00036 #define FE_DEC_TOWARDZERO 3 00037 #define FE_DEC_UPWARD 4 00038 #define FE_DEC_MAX 5 00039 00040 extern void __dfp_set_round (int); 00041 extern int __dfp_get_round (void); 00042 extern enum rounding __decGetRound (void); 00043 00044 /* FIXME: these should be in thread-local storage for runtime support. */ 00045 static enum rounding __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; 00046 00047 /* Set the decNumber rounding mode from the FE_DEC_* value in MODE. */ 00048 00049 void 00050 __dfp_set_round (int mode) 00051 { 00052 switch (mode) 00053 { 00054 case FE_DEC_DOWNWARD: 00055 __dfp_rounding_mode = DEC_ROUND_FLOOR; break; 00056 case FE_DEC_TONEAREST: 00057 __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break; 00058 case FE_DEC_TONEARESTFROMZERO: 00059 __dfp_rounding_mode = DEC_ROUND_HALF_UP; break; 00060 case FE_DEC_TOWARDZERO: 00061 __dfp_rounding_mode = DEC_ROUND_DOWN; break; 00062 case FE_DEC_UPWARD: 00063 __dfp_rounding_mode = DEC_ROUND_CEILING; break; 00064 default: 00065 /* We can't use assert in libgcc, so just return the default mode. */ 00066 __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break; 00067 } 00068 } 00069 00070 /* Return the decNumber rounding mode as an FE_DEC_* value. */ 00071 00072 int 00073 __dfp_get_round (void) 00074 { 00075 int mode; 00076 00077 switch (__dfp_rounding_mode) 00078 { 00079 case DEC_ROUND_FLOOR: 00080 mode = FE_DEC_DOWNWARD; break; 00081 case DEC_ROUND_HALF_EVEN: 00082 mode = FE_DEC_TONEAREST; break; 00083 case DEC_ROUND_HALF_UP: 00084 mode = FE_DEC_TONEARESTFROMZERO; break; 00085 case DEC_ROUND_DOWN: 00086 mode = FE_DEC_TOWARDZERO; break; 00087 case DEC_ROUND_CEILING: 00088 mode = FE_DEC_UPWARD; break; 00089 default: 00090 /* We shouldn't get here, but can't use assert in libgcc. */ 00091 mode = -1; 00092 } 00093 return mode; 00094 } 00095 00096 /* Return the decNumber version of the current rounding mode. */ 00097 00098 enum rounding 00099 __decGetRound (void) 00100 { 00101 return __dfp_rounding_mode; 00102 }
1.5.6