]> www.ginac.de Git - cln.git/commitdiff
Fix some conversions to cl_SF, cl_FF, and cl_DF.
authorRichard Kreckel <kreckel@ginac.de>
Tue, 9 Oct 2012 06:24:29 +0000 (08:24 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Tue, 9 Oct 2012 06:24:29 +0000 (08:24 +0200)
Some conversions failed to properly overflow/underflow with very large
exponents because of premature exponent truncation.

src/float/conv/cl_LF_to_DF.cc
src/float/conv/cl_LF_to_FF.cc
src/float/conv/cl_LF_to_SF.cc
src/float/dfloat/cl_DF.h
src/float/dfloat/elem/cl_DF_from_I.cc
src/float/ffloat/cl_FF.h
src/float/ffloat/elem/cl_FF_from_I.cc
src/float/sfloat/cl_SF.h
src/float/sfloat/elem/cl_SF_from_I.cc

index 9b8dc59ec3773ceef653a229928525c7d156b958..cd8877cda01a40c34c3f51c8453557c1ba53f348 100644 (file)
@@ -20,7 +20,7 @@ const cl_DF cl_LF_to_DF (const cl_LF& x)
 {
        // x entpacken:
        var cl_signean sign;
-       var sintL exp;
+       var sintE exp;
        var uintD* ptr;
        var uintC len;
        LF_decode(x, { return cl_DF_0; }, sign=,exp=,ptr=,len=,);
index fd4b67337e93a4ecda5a27677a84dde01c19648e..708bd3adb21b3f78163306a0d59d8fdf9c047019 100644 (file)
@@ -20,7 +20,7 @@ const cl_FF cl_LF_to_FF (const cl_LF& x)
 {
        // x entpacken:
        var cl_signean sign;
-       var sintL exp;
+       var sintE exp;
        var uintD* ptr;
        var uintC len;
        LF_decode(x, { return cl_FF_0; }, sign=,exp=,ptr=,len=,);
index 0649ebc385ca9ab55bc0fcf1dbcf7b2be93bd047..3f7a1b745817af9e7e2593af482a91f39c914ae4 100644 (file)
@@ -20,7 +20,7 @@ const cl_SF cl_LF_to_SF (const cl_LF& x)
 {
        // x entpacken:
        var cl_signean sign;
-       var sintL exp;
+       var sintE exp;
        var uintD* ptr;
        var uintC len;
        LF_decode(x, { return SF_0; }, sign=,exp=,ptr=,len=,);
index 381c6c7e43f86f1af2679f22f7100b883c0b17d7..7d93c8596db8a01fc2a7b6d0a997ddc57f11871e 100644 (file)
@@ -153,20 +153,20 @@ inline cl_heap_dfloat* allocate_dfloat (uint32 semhi, uint32 mlo)
 // encode_DF(sign,exp,mant)
 // liefert ein Double-Float.
 // > cl_signean sign: Vorzeichen, 0 für +, -1 für negativ.
-// > sintL exp: Exponent
+// > sintE exp: Exponent
 // > uintQ mant: Mantisse, sollte >= 2^DF_mant_len und < 2^(DF_mant_len+1) sein.
 // < cl_DF ergebnis: ein Double-Float
 // Der Exponent wird auf Überlauf/Unterlauf getestet.
-inline const cl_DF encode_DF (cl_signean sign, sintL exp, uintQ mant)
+inline const cl_DF encode_DF (cl_signean sign, sintE exp, uintQ mant)
 {
-      if (exp < (sintL)(DF_exp_low-DF_exp_mid))
+      if (exp < (sintE)(DF_exp_low-DF_exp_mid))
         { if (underflow_allowed())
             { throw floating_point_underflow_exception(); }
             else
             { return cl_DF_0; }
         }
       else
-      if (exp > (sintL)(DF_exp_high-DF_exp_mid))
+      if (exp > (sintE)(DF_exp_high-DF_exp_mid))
         { throw floating_point_overflow_exception(); }
       else
       return allocate_dfloat
@@ -179,21 +179,21 @@ inline const cl_DF encode_DF (cl_signean sign, sintL exp, uintQ mant)
 // encode_DF(sign,exp,manthi,mantlo)
 // liefert ein Double-Float.
 // > cl_signean sign: Vorzeichen, 0 für +, -1 für negativ.
-// > sintL exp: Exponent
+// > sintE exp: Exponent
 // > uintL manthi,mantlo: Mantisse 2^32*manthi+mantlo,
 //                        sollte >= 2^DF_mant_len und < 2^(DF_mant_len+1) sein.
 // < cl_DF ergebnis: ein Double-Float
 // Der Exponent wird auf Überlauf/Unterlauf getestet.
-inline const cl_DF encode_DF (cl_signean sign, sintL exp, uintL manthi, uintL mantlo)
+inline const cl_DF encode_DF (cl_signean sign, sintE exp, uintL manthi, uintL mantlo)
 {
-      if (exp < (sintL)(DF_exp_low-DF_exp_mid))
+      if (exp < (sintE)(DF_exp_low-DF_exp_mid))
         { if (underflow_allowed())
             { throw floating_point_underflow_exception(); }
             else
             { return cl_DF_0; }
         }
       else
-      if (exp > (sintL)(DF_exp_high-DF_exp_mid))
+      if (exp > (sintE)(DF_exp_high-DF_exp_mid))
         { throw floating_point_overflow_exception(); }
       else
       return allocate_dfloat
index 2a03eb36dd9f8dab00a356b551d12f3e8b716159..dddaa4473cd36f726da758db3fab9480ca6da755 100644 (file)
@@ -96,7 +96,7 @@ const cl_DF cl_I_to_DF (const cl_I& x)
           if (mant >= bit(DF_mant_len+1)) // rounding overflow?
             { mant = mant>>1; exp = exp+1; }
         }
-      return encode_DF(sign,(sintL)exp,mant);
+      return encode_DF(sign,(sintE)exp,mant);
       #else
       // Die NDS besteht aus msd, msdd, msddf und len weiteren Digits.
       // Das höchste in 2^64*msd+2^32*msdd+msddf gesetzte Bit ist Bit Nummer
@@ -132,7 +132,7 @@ const cl_DF cl_I_to_DF (const cl_I& x)
               if (manthi >= bit(DF_mant_len-32+1)) // rounding overflow?
                 { manthi = manthi>>1; exp = exp+1; }
         }   }
-      return encode_DF(sign,(sintL)exp,manthi,mantlo);
+      return encode_DF(sign,(sintE)exp,manthi,mantlo);
       #endif
 }
 
index 84010cec793c8b7294e3205d446605dab08ae3ee..370bffca907b19d232a42a67ddaf8a7a6992c4ab 100644 (file)
@@ -136,20 +136,20 @@ inline const cl_FF make_FF (cl_sint sign, unsigned int exp, cl_uint mant)
 // encode_FF(sign,exp,mant);
 // liefert ein Single-Float.
 // > cl_signean sign: Vorzeichen, 0 für +, -1 für negativ.
-// > sintL exp: Exponent
+// > sintE exp: Exponent
 // > uintL mant: Mantisse, sollte >= 2^FF_mant_len und < 2^(FF_mant_len+1) sein.
 // < object ergebnis: ein Single-Float
 // Der Exponent wird auf Überlauf/Unterlauf getestet.
-inline const cl_FF encode_FF (cl_signean sign, sintL exp, uintL mant)
+inline const cl_FF encode_FF (cl_signean sign, sintE exp, uintL mant)
 {
-       if (exp < (sintL)(FF_exp_low-FF_exp_mid))
+       if (exp < (sintE)(FF_exp_low-FF_exp_mid))
                { if (underflow_allowed())
                        { throw floating_point_underflow_exception(); }
                        else
                        { return cl_FF_0; }
                }
        else
-       if (exp > (sintL)(FF_exp_high-FF_exp_mid))
+       if (exp > (sintE)(FF_exp_high-FF_exp_mid))
                { throw floating_point_overflow_exception(); }
        else
        return make_FF(sign, exp+FF_exp_mid, mant & (bit(FF_mant_len)-1));
index 64f6080b89aa82ad10244ff03e95fdf5a6f840c0..e26e7de1e3db58bf8532533fafd0800221890846 100644 (file)
@@ -113,7 +113,7 @@ const cl_FF cl_I_to_FF (const cl_I& x)
             { mant = mant>>1; exp = exp+1; }
         }
       #endif
-      return encode_FF(sign,(sintL)exp,mant);
+      return encode_FF(sign,(sintE)exp,mant);
 }
 
 }  // namespace cln
index ca3b6e7b83568a27146879f86a9a139c5fe5c041..450601646cf9b9edb70468d7b755ab187fc752f4 100644 (file)
@@ -97,20 +97,20 @@ inline uintL SF_mant (const cl_SF& x)
 // encode_SF(sign,exp,mant)
 // liefert ein Short-Float.
 // > cl_signean sign: Vorzeichen, 0 für +, -1 für negativ.
-// > sintL exp: Exponent
+// > sintE exp: Exponent
 // > uintL mant: Mantisse, sollte >= 2^SF_mant_len und < 2^(SF_mant_len+1) sein.
 // < object ergebnis: ein Short-Float
 // Der Exponent wird auf Überlauf/Unterlauf getestet.
-inline const cl_SF encode_SF (cl_signean sign, sintL exp, uintL mant)
+inline const cl_SF encode_SF (cl_signean sign, sintE exp, uintL mant)
 {
-       if (exp < (sintL)(SF_exp_low-SF_exp_mid))
+       if (exp < (sintE)(SF_exp_low-SF_exp_mid))
          { if (underflow_allowed())
              { throw floating_point_underflow_exception(); }
              else
              { return SF_0; }
          }
        else
-       if (exp > (sintL)(SF_exp_high-SF_exp_mid))
+       if (exp > (sintE)(SF_exp_high-SF_exp_mid))
          { throw floating_point_overflow_exception(); }
        else
        return make_SF(sign, exp+SF_exp_mid, mant);
index 5e778304716b1aeb5abdffb3620fde6b644a80f9..9a89e8195a158bb8b5d743e1cbc3dbfe6d18767a 100644 (file)
@@ -112,7 +112,7 @@ const cl_SF cl_I_to_SF (const cl_I& x)
             { mant = mant>>1; exp = exp+1; }
         }
       #endif
-      return encode_SF(sign,(sintL)exp,mant);
+      return encode_SF(sign,(sintE)exp,mant);
 }
 
 }  // namespace cln