2 ##########################################################################
7 # IeeeCC754 or IEEE 754 Compliance Checker is a precision and range #
8 # independent tool to test whether an implementation of #
9 # floating-point arithmetic (in hardware or software) is compliant #
10 # with the principles of the IEEE 754-854 floating-point standards. #
11 # You can find out more about the testing tool IeeeCC754 at #
13 # http://win-www.uia.ac.be/u/cant/ieeecc754.html #
15 # This tool is in parts based on and greatly benefited from the #
16 # the program FPTEST developed by Jerome Coonen. For a full #
17 # description of the extensions to FPTEST and a reference to #
18 # the original Coonen program, please refer to the URL given above. #
19 # For the options available with the program IeeeCC754 and its #
20 # compatibility with David Hough's hexadecimal UCB format, we #
21 # also refer to the file readme.usage. #
23 # Usage: see readme.usage #
25 # Responsible authors: #
30 # Johan Bogo (1998-1999) #
31 # Tim Gevers (10-12/2000) #
32 # Debby Ooms (1996-1997) #
33 # Geert Vermuyten (1996-1997) #
34 # Dennis Verschaeren (09/1996-06/2000) #
36 # Copyright (C) 2000 University of Antwerp #
38 # This program can be obtained from the authors, free, but WITHOUT ANY #
39 # WARRANTY; without even the implied warranty of MERCHANTABILITY or #
40 # FITNESS FOR A PARTICULAR PURPOSE. #
43 # Brigitte.Verdonk@uia.ua.ac.be #
44 # Department of Mathematics and Computer Science #
45 # University of Antwerp (UIA) #
46 # Universiteitsplein 1 #
47 # B2610 Antwerp, BELGIUM #
49 ##########################################################################
59 /***************************************************************************
60 * This is a class definition for floating point numbers (IEEE 754).
61 * It uses the bitstring class for storing the exponent and the mantissa.
62 ************************************************************************** */
68 #include <Bitstring.h>
80 #define MYBIG_ENDIAN 101
83 #ifndef MYLITTLE_ENDIAN
84 #define MYLITTLE_ENDIAN 102
88 // maximum chars for binary to decimal conversion
90 /**This is an abstract class defining floating-points as described in the IEEE 754 standard. It uses the Bitstring class to represent the mantissa and exponent
91 separately. The hidden bit is always present in the mantissa and needs to be defined for input and output in a hexadecimal form.\\
93 There are three functions that need to be overloaded: SetRound(), GetExceptions(), SetEnvironment(). The first one must set the rounding mode of the library,
94 according to the rounding mode stored in the environment \textit{fpEnv}. This
95 can be done by calling the function GetFPRound() which returns the value actual rounding mode. GetExceptions() needs to convert the exceptions stored in the
96 testing library to the exceptions located in the environment \textit{fpEnv}.
97 To set the exceptions in the environment the functions: SetFPDivByZero(), SetFPInvalid(), SetFPUnderflow(), SetFPOverflow(), SetFPInexact() can be used.
98 The last function SetEnvironment() must set the library default environment.
107 ///Little or Big Endian
110 /**The representation of a floating-point environment. \\
111 Bit positions and values: \begin{itemize}
112 \item 0: divide by zero
117 \item 21 - 22 : rounding mode
119 \item 00: round to nearest
122 \item 11: round to zero
125 static Bitstring fpEnv;
127 ///The sign of the floating-point number
129 ///Hidden bit (yes/no)
131 ///The size of the mantissa
139 /**Checks if the hardware is big or little endian. This function is only
140 needed to correctly convert a FP to a hardware floating-point*/
141 static void CheckEndian();
143 /**Set the library rounding mode. This member function needs to be
144 overloaded when testing a floating-point implementation. The tester should
145 call his library function(s) to set the rounding mode corresponding the
146 one saved in fpEnv.*/
147 void SetLibRound(){};
148 /**Get library exceptions. This member functions needs to be overloaded
149 when testing a floating-point implementation. The tester should call his
150 function(s) to get the occured exceptions in his library and set them in
151 the fpEnv with SetFPDivByZero(), SetFPInvalid(),...*/
152 void GetLibExceptions(){};
153 /**Get FP rounding mode stored in fpEnv
154 @return the rounding mode \\ \begin{tabular}{ccl} 0 &:& round to nearest $(RM\_NEAR)$ \\
155 1 &:& round up (RM\_UP) \\
156 2 &:& round down $(RM\_DOWN)$ \\
157 3 &:& round to zero $(RM\_ZERO)$
162 ///Sets the divide by zero exception in fpEnv
163 void SetFPDivByZero(){fpEnv.Set(0);}
164 ///Sets the invalid exception in fpEnv
165 void SetFPInvalid() {fpEnv.Set(1);}
166 ///Sets the underflow exception in fpEnv
167 void SetFPUnderflow(){fpEnv.Set(2);}
168 ///Sets the overflow exception in fpEnv
169 void SetFPOverflow() {fpEnv.Set(3);}
170 ///Sets the inexact exception in fpEnv
171 void SetFPInexact() {fpEnv.Set(4);}
177 ///The size of the exponent
180 char *decimal; // binary to decimal conversion
184 /**Constructor setting the size of the exponent, the mantissa and the
186 @param sizeM the size of the mantissa
187 @param sizeE the size of the exponent
188 @param hiddenbit if there is a hidden bit (0: false / 1: true)*/
189 FP(int sizeM, int sizeE,int hiddenbit=0);
190 /**Constructor setting the size of the exponent,the mantissa and the
191 hidden bit. It initializes the floating-point number with a bitstring.
192 The bitstring must have the following form (sign exp (h) mant)
193 @param fp a bitstring containing the hardware reprecentation
195 @param sizeM the size of the mantissa
196 @param sizeE the size of the exponent
197 @param hiddenbit if there is a hidden bit (0: false / 1: true) */
198 FP(Bitstring &fp,int sizeM, int sizeE,int hiddenbit=0);
200 @param copy an other FP object*/
206 ///returns true (1) if there is a hidden bit
207 int Hidden(){return hidden;};
208 /**returns or sets the sign
209 @param sgn the new sign \\ \begin{tabular}{rcl} 1 &:& negative \\
213 @return the current sign or the previous depending \it{sgn}
215 int Sign(int sgn=-1);
217 /**Returns the mantissa
218 @return the mantissa hidden bit included (if defined)*/
219 Bitstring & GetMantissa();
220 /**Returns the exponent
221 @return the exponent*/
222 Bitstring & GetExponent();
224 @param mantissa the new mantissa including the hidden bit (if defined)
225 @return the previous mantissa*/
226 Bitstring PutMantissa(Bitstring &mantissa);
228 @param exponent the new exponent.
229 @return the previous exponent.*/
230 Bitstring PutExponent(Bitstring &exponent);
232 /**Checks if the floating-point is a Zero
233 @return \begin{tabular}{rcl} 1 &:& is a Zero\\
238 /**Checks if the floating-point is a negative Zero
239 @return \begin{tabular}{rcl} 1 &:& is a neg Zero\\
240 0 &:& is not a neg Zero
244 /**Checks if the floating-point is a NaN
245 @return \begin{tabular}{rcl} 1 &:& is a NaN \\
249 /**Creates a quiet NaN */
252 /**Assignment operator
253 @param copy an other FP object to be copied
255 FP& operator = (const FP ©);
256 /**Assignment operator
257 @param copy an Bitstring object to be converted to a FP object
259 FP& operator = (const Bitstring ©);
261 /**Set the default library environment rounding mode. This member function
262 needs to be overloaded when testing a floating-point implementation. The
263 tester should call his library function(s) to set the default library
264 environment. Normaly this means to clear the exception flags and restoring
265 the rounding mode to round to nearest.*/
266 void SetLibEnvironment(){};
268 /** Sets the rounding mode in the fpEnv to rm
269 @param rm next values a defined \\ \begin{tabular}{rcl} 0 &:& round to nearest $(RM\_NEAR)$ \\
270 1 &:& round up (RM\_UP) \\
271 2 &:& round down $(RM\_DOWN)$ \\
272 3 &:& round to zero $(RM\_ZERO)$
275 void SetFPRound (int rm);
276 ///Clears the environment (fpEnv)
277 void ClearFPEnvironment();
278 /**Returns the exceptions stored in fpEnv as a Bitstring
279 @return a Bitstring with next bit positions set, depending the exception \\\begin{tabular}{rcl}
280 0 &:& divide by zero\\
286 void GetFPExceptions(Bitstring);
289 /**Chekcs if there has occured a divide by zero exception
290 @return\begin{tabular}{rcl} 1 &:& divide by zero exception\\
291 0 &:& no divide by zero exception
293 int GetFPDivByZero(){return fpEnv.GetBit(0);}
294 /**chekcs if there has occured a invalid exception
295 @return\begin{tabular}{rcl} 1 &:& invalid exception \\
296 0 &:& no invalid exception
298 int GetFPInvalid() {//cout << "fpEnv.GetBit(1)" << fpEnv.GetBit(1);
299 return fpEnv.GetBit(1);}
300 /**chekcs if there has occured a underflow exception
301 @return\begin{tabular}{rcl} 1 &:& underflow exception \\
302 0 &:& no underflow exception
304 int GetFPUnderflow(){return fpEnv.GetBit(2);}
305 /**chekcs if there has occured a overflow exception
306 @return\begin{tabular}{rcl} 1 &:& overflow exception \\
307 0 &:& no overflow exception
309 int GetFPOverflow() {return fpEnv.GetBit(3);}
310 /**chekcs if there has occured a inexact exception
311 @return\begin{tabular}{rcl} 1 &:& inexact exception \\
312 0 &:& no inexact exception
314 int GetFPInexact() {return fpEnv.GetBit(4);}
319 ///Overloaded output operator
320 friend ostream& operator << (ostream& outs, FP &outstr);
322 friend istream& operator >> (istream& ins, FP &instr);
326 //@Include: MyFloat.h MyDouble.h MyQuad.h FpSim.h Bitstring.h UCB.h dlist.h stack.h ../Calculator/FPcalculator.h