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 ##########################################################################
65 int FP::Endian = NOT_KNOWN;
66 Bitstring FP::fpEnv(32);
71 //cout << "fpEnv = " << fpEnv << endl;
72 fpEnv.SubBitstring(21,temp);
73 //cout << "temp = " << temp << endl;
77 void FP::ClearFPEnvironment()
86 /***********************************************************************
87 * Member: CheckEndian()
90 ***********************************************************************/
91 void FP::CheckEndian()
93 // char *tmp = new char[4];
95 unsigned long tmplong =1;
97 if (FP::Endian == NOT_KNOWN)
101 Endian= MYLITTLE_ENDIAN;
103 Endian= MYBIG_ENDIAN;
110 /***********************************************************************
111 * Member: FP () Constructor
112 * Purpose: Create a floating point number
114 ***********************************************************************/
126 /***********************************************************************
127 * Member: FP (int sizeM, int sizeE, int hiddenbit=0) Constructor
128 * Purpose: Create a floating point number with the size of the exponent
129 * and the mantissa defined and if the there is a hidden bit
133 ***********************************************************************/
134 FP::FP(int sizeM, int sizeE,int hiddenbit)
147 /***********************************************************************
148 * Member: FP (Bitstring &fp,int sizeM,int sizeE,int hiddenbit=0) Constructor
149 * Purpose: Create a floating point number with the size of the exponent
150 * and the mantissa defined and if the there is a hidden bit
151 * 0 -> false, 1 -> true and initialize it with "fp" as a
152 * bit representation of a IEEE 754 floating point number
154 ***********************************************************************/
156 FP::FP(Bitstring &fp,int sizeM, int sizeE,int hiddenbit)
166 mant = Bitstring(sizeMant);
168 exp = Bitstring(sizeExp);
173 // cout << "exp (voor) = " << exp << endl;
175 fp.SubBitstring(1,exp);
176 fp.SubBitstring(sizeExp+1,mant);
179 fp.SubBitstring(0,mant);
182 /***********************************************************************
183 * Member: FP(FP & copy) Copy constructor
184 * Purpose: Create a floating point number with initiale value the
185 * floating point "copy"
187 ***********************************************************************/
193 hidden = copy.hidden;
194 sizeExp = copy.sizeExp;
195 sizeMant = copy.sizeMant;
198 if (copy.decimal != NULL) {
199 decimal = new char[256];
200 strcpy(decimal,copy.decimal);
204 // cout << "copy decimal" << decimal << endl << flush;
209 FP& FP::operator = ( const FP ©)
212 hidden = copy.hidden;
213 sizeExp = copy.sizeExp;
214 sizeMant = copy.sizeMant;
217 if (copy.decimal != NULL) {
218 decimal = new char[maxstr];
219 strcpy(decimal,copy.decimal);
223 // cout << "copy decimal" << decimal << endl << flush;
228 int FP::Sign(int sgn)
233 if ((sgn == 0)||(sgn==1))
239 Bitstring & FP::GetMantissa()
241 // cout << "sizeMant = " << sizeMant << endl;
245 Bitstring & FP::GetExponent()
250 Bitstring FP::PutMantissa(Bitstring &mantissa)
252 Bitstring temp(mant);
255 // mant.Resize(sizeMant+hidden); //in case the mantisa is too big
259 Bitstring FP::PutExponent(Bitstring &exponent)
264 exp.Resize(sizeExp); //in case the mantisa is too big
271 Bitstring fullExp(sizeExp);
272 Bitstring fullMant(sizeMant+hidden);
275 for (i=0; i < sizeExp ; i++)
279 for (i=0; i < sizeMant ; i++)
280 fullMant.PutBit(i,0);
282 fullMant.PutBit(0,1);
283 return(fullMant != mant);
292 Bitstring fullExp(sizeExp);
293 Bitstring fullMant(sizeMant);
294 if ((sizeMant > 0) && (sizeExp > 0)) {
295 for (i=0; i < sizeExp; i++)
297 for (i=0; i < sizeMant ; i++)
298 fullMant.PutBit(i,0);
299 return ((fullExp == exp) && (fullMant != mant));
308 Bitstring fullExp(sizeExp);
309 Bitstring fullMant(sizeMant);
310 if ((sizeMant > 0) && (sizeExp > 0)) {
311 for (i=0; i < sizeExp ; i++)
313 if (fullExp == exp) {
317 for (;i < sizeMant;i++)
318 if (mant.GetBit(i) != 0)
332 Bitstring fullExp(sizeExp);
333 Bitstring fullMant(sizeMant);
334 if ((sizeMant > 0) && (sizeExp > 0)) {
335 for (i=0; i < sizeExp ; i++)
337 if (fullExp == exp) {
341 for (;i < sizeMant;i++)
342 if (mant.GetBit(i) != 0)
354 void FP::CreateQFPNan()
358 for (i=0; i < sizeExp ; i++)
361 mant.PutBit(sizeMant-1,1); //PLAATS
365 FP& FP::operator = (const Bitstring ©)
367 copy.SubBitstring(0,mant);
368 copy.SubBitstring(sizeMant,exp);
369 sign = copy.GetBit(sizeMant+sizeExp);
373 mant.Resize(sizeMant+1);
375 Bitstring emptyExp(sizeExp);
376 for (int i=0; i< sizeExp; i++)
377 emptyExp.PutBit(i,0);
379 if (emptyExp != exp) //denormalized
380 mant.PutBit(sizeMant,1);
387 void FP::SetFPRound (int rm)
391 // cout << "fpEnv (SetFPR) = " << fpEnv << endl;
405 // cout << "fpEnv = " << fpEnv << endl;
408 void FP::GetFPExceptions(Bitstring E)
410 fpEnv.SubBitstring(0,E);
413 ostream& operator << (ostream& outs, FP &strout)
416 if (strout.decimal != NULL) // decimal representation
417 outs << strout.decimal;
420 if (strout.sizeExp > 0) {
425 outs << " " << hex << strout.exp << " " << strout.mant;
428 outs << hex << strout.mant;
431 if (strout.sizeExp > 0)
432 size = 1+strout.sizeExp+strout.sizeMant;
434 size = strout.sizeMant;
435 Bitstring merge(size);
436 if (strout.sizeExp > 0) {
441 for (i = 0; i < strout.sizeExp;i++)
442 merge.PutBit(i+1,strout.exp.GetBit(i));
443 for (i = 0; i < strout.sizeMant;i++)
444 merge.PutBit(1+strout.sizeExp+i,strout.mant.GetBit(i));
447 for (i = 0; i < strout.sizeMant;i++)
448 merge.PutBit(i,strout.mant.GetBit(i));
456 istream& operator >> (istream& ins, FP &instr)
461 instr.StringToBitstr(str);
469 if ((sizeMant > 0) && (sizeExp > 0)) {
470 for (i=0; i < sizeExp ; i++)
471 if ( exp.GetBit(i) != 0 ){
477 for (;i < sizeMant;i++)
478 if (mant.GetBit(i) != 0)
490 if ((sizeMant > 0) && (sizeExp > 0)) {
491 for (i=0; i < sizeExp ; i++)
492 if ( exp.GetBit(i) != 0 ){
498 for (;i < sizeMant;i++)
499 if (mant.GetBit(i) != 0)