X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;f=src%2Ffloat%2Fdfloat%2Fcl_DF.h;h=701a0b70258401bd08614d5805755ceb3e450788;hb=8b3d91dec77438c0fe679b10869ab29e6cdeba58;hp=1cb787086df53d978e1b7126586a4d3a908a134b;hpb=dd9e0f894eec7e2a8cf85078330ddc0a6639090b;p=cln.git diff --git a/src/float/dfloat/cl_DF.h b/src/float/dfloat/cl_DF.h index 1cb7870..701a0b7 100644 --- a/src/float/dfloat/cl_DF.h +++ b/src/float/dfloat/cl_DF.h @@ -3,21 +3,36 @@ #ifndef _CL_DF_H #define _CL_DF_H -#include "cl_number.h" -#include "cl_malloc.h" +#include "cln/number.h" +#include "cln/malloc.h" #include "cl_low.h" #include "cl_F.h" +#ifdef FAST_DOUBLE +#include "cl_N.h" +#include "cl_F.h" +#endif + +namespace cln { + typedef // 64-bit float in IEEE format #if (cl_word_size==64) // Sign/Exponent/Mantissa 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)) @@ -112,7 +127,7 @@ inline cl_heap_dfloat* allocate_dfloat (uint32 semhi, uint32 mlo) #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 @@ -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. +// > cl_signean sign: Vorzeichen, 0 für +, -1 für negativ. // > sintL 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. +// Der Exponent wird auf Überlauf/Unterlauf getestet. inline const cl_DF encode_DF (cl_signean sign, sintL exp, uintQ mant) { if (exp < (sintL)(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(); } + { 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. +// > cl_signean sign: Vorzeichen, 0 für +, -1 für negativ. // > sintL 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. +// Der Exponent wird auf Überlauf/Unterlauf getestet. inline const cl_DF encode_DF (cl_signean sign, sintL exp, uintL manthi, uintL mantlo) { if (exp < (sintL)(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(); } + { 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, @@ -305,4 +318,6 @@ inline const cl_DF cl_double_to_DF (const dfloatjanus& 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 */