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 ##########################################################################
64 /*class implementation*/
66 /***********************************************************************
67 * Member: GetBin(char v)
68 * Purpose: returns a Bitstring with the corresponding binary value of "v"
69 * Return: Bitstring with binary value of "v"
70 ***********************************************************************/
71 void Hex::GetBin(char v)
73 // cout << "char = " << v << endl;
78 // Bitstring::StringToBitstr("0000");
82 // StringToBitstr("0001");
86 // StringToBitstr("0010");
90 // StringToBitstr("0011");
94 // StringToBitstr("0100");
98 // StringToBitstr("0101");
102 // StringToBitstr("0110");
106 // StringToBitstr("0111");
110 // StringToBitstr("1000");
114 // StringToBitstr("1001");
119 // StringToBitstr("1010");
124 // StringToBitstr("1011");
129 // StringToBitstr("1100");
134 // StringToBitstr("1101");
139 // StringToBitstr("1110");
144 // StringToBitstr("1111");
150 /***********************************************************************
151 * Member: GetHex(Bitstring &b)
152 * Purpose: It gives the character that is represented in "b"
153 * Return: returns b as a character
154 ***********************************************************************/
155 char Hex::GetHex(Bitstring &b) const
161 temp.StringToBitstr("0000");
165 temp.StringToBitstr("0001");
169 temp.StringToBitstr("0010");
173 temp.StringToBitstr("0011");
177 temp.StringToBitstr("0100");
181 temp.StringToBitstr("0101");
185 temp.StringToBitstr("0110");
189 temp.StringToBitstr("0111");
193 temp.StringToBitstr("1000");
197 temp.StringToBitstr("1001");
201 temp.StringToBitstr("1010");
205 temp.StringToBitstr("1011");
209 temp.StringToBitstr("1100") ;
213 temp.StringToBitstr("1101");
217 temp.StringToBitstr("1110");
221 temp.StringToBitstr("1111");
230 /***********************************************************************
231 * Member: Hex() Constructor
232 * Purpose: Create empty hexadecimal bitstring
234 ***********************************************************************/
239 /***********************************************************************
240 * Member: Bitstring(unsigned long size) Constructor
241 * Purpose: Create a hexadecimal bitstring of size "size"*4
243 ***********************************************************************/
244 Hex::Hex(unsigned long size)
250 /***********************************************************************
251 * Member: Hex(char * str) Constructor
252 * Purpose: Create hexadecimal bitstring with "str" as initiale value
254 ***********************************************************************/
260 length = strlen(hstr)*4;
261 lengthT= sizeof(unsigned long) * 8;
262 lengthBlock = (length/lengthT)+1;
264 bitstr = new unsigned long [lengthBlock];
266 for (i=0;i<lengthBlock;i++)
270 for (i= (length/4) -1; i >= 0; i--)
272 t1.GetBin(hstr[i--]);
286 /***********************************************************************
287 * Member: Hex(Bitstring & copy)
288 * Purpose: Create a hexadecimal bitstring with initiale value the bitstring
291 ***********************************************************************/
292 Hex::Hex(const Bitstring ©)
296 length = copy.Length();
297 lengthT = sizeof(unsigned long)*8;
298 lengthBlock = (length /lengthT) +1;
300 bitstr = new unsigned long [lengthBlock];
302 for (i=0 ; i< lengthBlock; i++)
311 /***********************************************************************
312 * Member: Resize (unsigned long len)
313 * Purpose: Change the length of the bitstring to "len"*4. If the new length is
314 * larger then the length, the bitstring is appended with 0, else
315 * the bitstring is truncated to the new length "len"*4
316 * Return: Previous length
317 ***********************************************************************/
318 unsigned long Hex::Resize(unsigned long len)
320 return Bitstring::Resize(len*4);
323 /***********************************************************************
324 * Member: BitstrToString()
325 * Purpose: Converts a hexadecimal bitstring to a C-string
326 * Return: length >0 -> The C-string
327 * else -> "Bitstring is empty"
328 ***********************************************************************/
329 void Hex::BitstrToString(char* out) const
334 out= new char[(length/4)+2];
335 for (i = 0 ;i< length/4; i++)
337 // cout << "i = " << i << endl << flush;
338 SubBitstring(i*4,temp);
339 // cout << "temp = " << temp << endl << flush;
340 out[length/4 -i -1]=GetHex(temp);
342 out[(length/4)]='\0';
345 /***********************************************************************
346 * Member: StringToBitstr(char *str)
347 * Purpose: Converts a C-string to a hexadecimal bitstring
348 * Return: converted bitstring
349 ***********************************************************************/
350 void Hex::StringToBitstr(char *hstr)
353 Bitstring t1(4),t2(4);
356 length = strlen(hstr)*4;
357 lengthT= sizeof(unsigned long) * 8;
358 if (length % lengthT == 0)
359 lengthBlock = length/lengthT;
361 lengthBlock = (length/lengthT)+1;
364 // cout << "lengthBlock = " << lengthBlock << endl << flush;
365 bitstr = new unsigned long [lengthBlock];
366 for (i=0;i<lengthBlock;i++)
369 for (i= 0; i < length/4;) {
370 // cout << "hstr[i] = " << hstr[i] << endl << flush;
372 for (k = 0; k < 7;k++) {
374 tmp += hstr[i++] - '0';
376 tmp += hstr[i++] - 'a' + 10;
377 // cout << hex << tmp << endl;
381 tmp += hstr[i++] - '0';
383 tmp += hstr[i++] - 'a' + 10;
384 // cout << "tmp = " << hex << tmp << endl;
386 // cout << hex << bitstr[j] << " " << flush;
390 for (i= (length/4) -1; i >= 0; i--)
392 t1.GetBin(hstr[i--]);
393 // cout << "t1 = " << t1 << endl << flush;
397 // cout << "t2 = " << t2 << endl << flush;
399 // cout << "t2 = " << t2 << endl << flush;