#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;
#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;
#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;
#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))
#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
#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 */
#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 */
{
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
// 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); \
) \
&& 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 */ \
} \
&& (((~_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); } \
) ) \
&& 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 */\
} \
&& (((~_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); } \
#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,
// 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 */