]> www.ginac.de Git - cln.git/blobdiff - src/float/dfloat/cl_DF.h
Finalize CLN 1.3.7 release.
[cln.git] / src / float / dfloat / cl_DF.h
index 1cb787086df53d978e1b7126586a4d3a908a134b..6951bf23ea38f550322e243f72d7e8ecdbba1b0c 100644 (file)
@@ -3,10 +3,17 @@
 #ifndef _CL_DF_H
 #define _CL_DF_H
 
-#include "cl_number.h"
-#include "cl_malloc.h"
-#include "cl_low.h"
-#include "cl_F.h"
+#include "cln/number.h"
+#include "cln/malloc.h"
+#include "base/cl_low.h"
+#include "float/cl_F.h"
+
+#ifdef FAST_DOUBLE
+#include "base/cl_N.h"
+#include "float/cl_F.h"
+#endif
+
+namespace cln {
 
 typedef // 64-bit float in IEEE format
        #if (cl_word_size==64)
@@ -14,10 +21,18 @@ typedef // 64-bit float in IEEE format
          uint64
        #else
          // Sign/Exponent/MantissaHigh and MantissaLow
-         #if CL_CPU_BIG_ENDIAN_P
-           struct { uint32 semhi, mlo; }
+         #if defined(double_wordorder_bigendian_p)
+           #if double_wordorder_bigendian_p
+             struct { uint32 semhi, mlo; }
+           #else
+             struct { uint32 mlo, semhi; }
+           #endif
          #else
-           struct { uint32 mlo, semhi; }
+           #if CL_CPU_BIG_ENDIAN_P
+             struct { uint32 semhi, mlo; }
+           #else
+             struct { uint32 mlo, semhi; }
+           #endif
          #endif
        #endif
        dfloat;
@@ -61,7 +76,7 @@ extern cl_class cl_class_dfloat;
 #if (cl_word_size==64)
 inline cl_heap_dfloat* allocate_dfloat (dfloat eksplicit)
 {
-       cl_heap_dfloat* p = (cl_heap_dfloat*) cl_malloc_hook(sizeof(cl_heap_dfloat));
+       cl_heap_dfloat* p = (cl_heap_dfloat*) malloc_hook(sizeof(cl_heap_dfloat));
        p->refcount = 1;
        p->type = &cl_class_dfloat;
        p->representation.eksplicit = eksplicit;
@@ -70,7 +85,7 @@ inline cl_heap_dfloat* allocate_dfloat (dfloat eksplicit)
 #else
 inline cl_heap_dfloat* allocate_dfloat (uint32 semhi, uint32 mlo)
 {
-       cl_heap_dfloat* p = (cl_heap_dfloat*) cl_malloc_hook(sizeof(cl_heap_dfloat));
+       cl_heap_dfloat* p = (cl_heap_dfloat*) malloc_hook(sizeof(cl_heap_dfloat));
        p->refcount = 1;
        p->type = &cl_class_dfloat;
        p->representation.eksplicit.semhi = semhi;
@@ -93,7 +108,7 @@ inline cl_heap_dfloat* allocate_dfloat (uint32 semhi, uint32 mlo)
 #if (cl_word_size==64)
 // DF_decode(obj, zero_statement, sign=,exp=,mant=);
 // zerlegt ein Double-Float obj.
-// Ist obj=0.0, wird zero_statement ausgeführt.
+// Ist obj=0.0, wird zero_statement ausgeführt.
 // Sonst: cl_signean sign = Vorzeichen (0 = +, -1 = -),
 //        sintL exp = Exponent (vorzeichenbehaftet),
 //        uintQ mant = Mantisse (>= 2^DF_mant_len, < 2^(DF_mant_len+1))
@@ -106,13 +121,13 @@ inline cl_heap_dfloat* allocate_dfloat (uint32 semhi, uint32 mlo)
         { zero_statement } /* e=0 -> Zahl 0.0 */                       \
         else                                                           \
         { exp_zuweisung (sintL)(uexp - DF_exp_mid); /* Exponent */     \
-          unused (sign_zuweisung ((sint64)_x >> 63)); /* Vorzeichen */ \
+          cl_unused (sign_zuweisung ((sint64)_x >> 63)); /* Vorzeichen */      \
           mant_zuweisung (bit(DF_mant_len) | (_x & (bit(DF_mant_len)-1))); \
     }   }
 #else
 // DF_decode2(obj, zero_statement, sign=,exp=,manthi=,mantlo=);
 // zerlegt ein Double-Float obj.
-// Ist obj=0.0, wird zero_statement ausgeführt.
+// Ist obj=0.0, wird zero_statement ausgeführt.
 // Sonst: cl_signean sign = Vorzeichen (0 = +, -1 = -),
 //        sintL exp = Exponent (vorzeichenbehaftet),
 //        uintL manthi,mantlo = Mantisse 2^32*manthi+mantlo
@@ -127,7 +142,7 @@ inline cl_heap_dfloat* allocate_dfloat (uint32 semhi, uint32 mlo)
         { zero_statement } /* e=0 -> Zahl 0.0 */                       \
         else                                                           \
         { exp_zuweisung (sintL)(uexp - DF_exp_mid); /* Exponent */     \
-          unused (sign_zuweisung sign_of((sint32)(semhi))); /* Vorzeichen */\
+          cl_unused (sign_zuweisung sign_of((sint32)(semhi))); /* Vorzeichen */\
           manthi_zuweisung (bit(DF_mant_len-32) | (semhi & (bit(DF_mant_len-32)-1))); \
           mantlo_zuweisung mlo;                                                \
     }   }
@@ -137,22 +152,22 @@ inline cl_heap_dfloat* allocate_dfloat (uint32 semhi, uint32 mlo)
 #if (cl_word_size==64)
 // encode_DF(sign,exp,mant)
 // liefert ein Double-Float.
-// > cl_signean sign: Vorzeichen, 0 für +, -1 für negativ.
-// > sintL exp: Exponent
+// > cl_signean sign: Vorzeichen, 0 für +, -1 für negativ.
+// > 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)
+// Der Exponent wird auf Überlauf/Unterlauf getestet.
+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())
-            { cl_error_floating_point_underflow(); }
+            { throw floating_point_underflow_exception(); }
             else
             { return cl_DF_0; }
         }
       else
-      if (exp > (sintL)(DF_exp_high-DF_exp_mid))
-        { cl_error_floating_point_overflow(); }
+      if (exp > (sintE)(DF_exp_high-DF_exp_mid))
+        { throw floating_point_overflow_exception(); }
       else
       return allocate_dfloat
         (  ((sint64)sign & bit(63))                  /* Vorzeichen */
@@ -163,23 +178,23 @@ inline const cl_DF encode_DF (cl_signean sign, sintL exp, uintQ mant)
 #else
 // encode_DF(sign,exp,manthi,mantlo)
 // liefert ein Double-Float.
-// > cl_signean sign: Vorzeichen, 0 für +, -1 für negativ.
-// > sintL exp: Exponent
+// > cl_signean sign: Vorzeichen, 0 für +, -1 für negativ.
+// > 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)
+// Der Exponent wird auf Überlauf/Unterlauf getestet.
+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())
-            { cl_error_floating_point_underflow(); }
+            { throw floating_point_underflow_exception(); }
             else
             { return cl_DF_0; }
         }
       else
-      if (exp > (sintL)(DF_exp_high-DF_exp_mid))
-        { cl_error_floating_point_overflow(); }
+      if (exp > (sintE)(DF_exp_high-DF_exp_mid))
+        { throw floating_point_overflow_exception(); }
       else
       return allocate_dfloat
         (  ((sint32)sign & bit(31))                       /* Vorzeichen */
@@ -196,7 +211,7 @@ inline double DF_to_double (const cl_DF& obj)
 {
        return TheDfloat(obj)->representation.machine_double;
 }
-// Überprüfen und Einpacken eines von den 'double'-Routinen gelieferten
+// Überprüfen und Einpacken eines von den 'double'-Routinen gelieferten
 // IEEE-Floats.
 // Klassifikation:
 //   1 <= e <= 2046 : normalisierte Zahl
@@ -204,14 +219,12 @@ inline double DF_to_double (const cl_DF& obj)
 //   e=0, m=0: vorzeichenbehaftete 0.0
 //   e=2047, m=0: vorzeichenbehaftete Infinity
 //   e=2047, m/=0: NaN
-// Angabe der möglicherweise auftretenden Sonderfälle:
-//   maybe_overflow: Operation läuft über, liefert IEEE-Infinity
+// Angabe der möglicherweise auftretenden Sonderfälle:
+//   maybe_overflow: Operation läuft über, liefert IEEE-Infinity
 //   maybe_subnormal: Ergebnis sehr klein, liefert IEEE-subnormale Zahl
 //   maybe_underflow: Ergebnis sehr klein und /=0, liefert IEEE-Null
 //   maybe_divide_0: Ergebnis unbestimmt, liefert IEEE-Infinity
 //   maybe_nan: Ergebnis unbestimmt, liefert IEEE-NaN
-  #include "cl_N.h"
-  #include "cl_F.h"
 #if (cl_word_size==64)
   #define double_to_DF(expr,ergebnis_zuweisung,maybe_overflow,maybe_subnormal,maybe_underflow,maybe_divide_0,maybe_nan)  \
     { var dfloatjanus _erg; _erg.machine_double = (expr);              \
@@ -221,7 +234,7 @@ inline double DF_to_double (const cl_DF& obj)
               )                                                                \
               && underflow_allowed()                                   \
              )                                                         \
-            { cl_error_floating_point_underflow(); } /* subnormal oder noch kleiner -> Underflow */\
+            { throw floating_point_underflow_exception(); } /* subnormal oder noch kleiner -> Underflow */\
             else                                                       \
             { ergebnis_zuweisung cl_DF_0; } /* +/- 0.0 -> 0.0 */       \
         }                                                              \
@@ -229,12 +242,12 @@ inline double DF_to_double (const cl_DF& obj)
             && (((~_erg.eksplicit) & ((uint64)bit(DF_exp_len+DF_mant_len)-bit(DF_mant_len))) == 0) /* e=2047 ? */\
            )                                                           \
         { if (maybe_nan && !((_erg.eksplicit<<(64-DF_mant_len)) == 0)) \
-            { cl_error_division_by_0(); } /* NaN, also Singularität -> "Division durch 0" */\
+            { throw division_by_0_exception(); } /* NaN, also Singularität -> "Division durch 0" */\
           else /* Infinity */                                          \
           if (!maybe_overflow || maybe_divide_0)                       \
-            { cl_error_division_by_0(); } /* Infinity, Division durch 0 */\
+            { throw division_by_0_exception(); } /* Infinity, Division durch 0 */\
             else                                                       \
-            { cl_error_floating_point_overflow(); } /* Infinity, Overflow */\
+            { throw floating_point_overflow_exception(); } /* Infinity, Overflow */\
         }                                                              \
       else                                                             \
         { ergebnis_zuweisung allocate_dfloat(_erg.eksplicit); }                \
@@ -249,7 +262,7 @@ inline double DF_to_double (const cl_DF& obj)
               )   )                                                       \
               && underflow_allowed()                                      \
              )                                                            \
-            { cl_error_floating_point_underflow(); } /* subnormal oder noch kleiner -> Underflow */\
+            { throw floating_point_underflow_exception(); } /* subnormal oder noch kleiner -> Underflow */\
             else                                                          \
             { ergebnis_zuweisung cl_DF_0; } /* +/- 0.0 -> 0.0           */\
         }                                                                 \
@@ -257,12 +270,12 @@ inline double DF_to_double (const cl_DF& obj)
             && (((~_erg.eksplicit.semhi) & ((uint32)bit(DF_exp_len+DF_mant_len-32)-bit(DF_mant_len-32))) == 0) /* e=2047 ?  */\
            )                                                              \
         { if (maybe_nan && !(((_erg.eksplicit.semhi<<(64-DF_mant_len)) == 0) && (_erg.eksplicit.mlo==0))) \
-            { cl_error_division_by_0(); } /* NaN, also Singularität -> "Division durch 0"  */\
+            { throw division_by_0_exception(); } /* NaN, also Singularität -> "Division durch 0"  */\
           else /* Infinity                                              */\
           if (!maybe_overflow || maybe_divide_0)                          \
-            { cl_error_division_by_0(); } /* Infinity, Division durch 0 */\
+            { throw division_by_0_exception(); } /* Infinity, Division durch 0 */\
             else                                                          \
-            { cl_error_floating_point_overflow(); } /* Infinity, Overflow */\
+            { throw floating_point_overflow_exception(); } /* Infinity, Overflow */\
         }                                                                 \
       else                                                                \
         { ergebnis_zuweisung allocate_dfloat(_erg.eksplicit.semhi,_erg.eksplicit.mlo); }  \
@@ -271,7 +284,7 @@ inline double DF_to_double (const cl_DF& obj)
 #endif
 
 // Liefert zu einem Double-Float x : (futruncate x), ein DF.
-// x wird von der 0 weg zur nächsten ganzen Zahl gerundet.
+// x wird von der 0 weg zur nächsten ganzen Zahl gerundet.
 extern const cl_DF futruncate (const cl_DF& x);
 
 // DF_to_I(x) wandelt ein Double-Float x, das eine ganze Zahl darstellt,
@@ -296,13 +309,13 @@ extern const cl_DF cl_RA_to_DF (const cl_RA& x);
 //   e=2047, m=0: vorzeichenbehaftete Infinity
 //   e=2047, m/=0: NaN
 
-// cl_double_to_DF(val) wandelt ein IEEE-Double-Float val in ein Double-Float um.
-extern cl_heap_dfloat* cl_double_to_DF_pointer (const dfloatjanus& val);
-inline const cl_DF cl_double_to_DF (const dfloatjanus& val)
-       { return cl_double_to_DF_pointer(val); }
+// cl_double_to_DF_pointer(val) wandelt ein IEEE-Double-Float val in ein Double-Float um.
+extern cl_heap_dfloat* cl_double_to_DF_pointer (const double val);
 
 // cl_DF_to_double(obj,&val);
 // wandelt ein Double-Float obj in ein IEEE-Double-Float val um.
 extern void cl_DF_to_double (const cl_DF& obj, dfloatjanus* val_);
 
+}  // namespace cln
+
 #endif /* _CL_DF_H */