#include "cln/ffloat_class.h"
#include "cln/dfloat_class.h"
#include "cln/lfloat_class.h"
+#include "cln/exception.h"
namespace cln {
// zerop(x) testet, ob (= x 0).
-extern cl_boolean zerop (const cl_F& x);
+extern bool zerop (const cl_F& x);
// minusp(x) testet, ob (< x 0).
-extern cl_boolean minusp (const cl_F& x);
+extern bool minusp (const cl_F& x);
// plusp(x) testet, ob (> x 0).
-extern cl_boolean plusp (const cl_F& x);
+extern bool plusp (const cl_F& x);
// cl_F_to_SF(x) wandelt ein Float x in ein Short-Float um und rundet dabei.
// cl_F_to_LF(x,len) wandelt ein Float x in ein Long-Float mit len Digits um
// und rundet dabei.
-// > uintC len: gewünschte Anzahl Digits, >=LF_minlen
+// > uintC len: gewünschte Anzahl Digits, >=LF_minlen
extern const cl_LF cl_F_to_LF (const cl_F& x, uintC len);
// Returns the smallest float format which guarantees at least n decimal digits
// in the mantissa (after the decimal point).
-extern float_format_t float_format (uintL n);
+extern float_format_t float_format (uintE n);
// cl_float(x,y) wandelt ein Float x in das Float-Format des Floats y um
-// und rundet dabei nötigenfalls.
+// und rundet dabei nötigenfalls.
// > x,y: Floats
// < ergebnis: (float x y)
extern const cl_F cl_float (const cl_F& x, const cl_F& y);
// cl_float(x,f) wandelt ein Float x in das Float-Format f um
-// und rundet dabei nötigenfalls.
+// und rundet dabei nötigenfalls.
// > x: ein Float
// > f: eine Float-Format-Spezifikation
// < ergebnis: (float x f)
extern const cl_F cl_float (const cl_F& x, float_format_t f);
// cl_float(x) wandelt eine reelle Zahl x in ein Float um
-// und rundet dabei nötigenfalls.
+// und rundet dabei nötigenfalls.
// > x: eine reelle Zahl
// < ergebnis: (float x)
-// Abhängig von default_float_format.
+// Abhängig von default_float_format.
inline const cl_F cl_float (const cl_F& x) { return x; }
// cl_float(x,y) wandelt ein Integer x in das Float-Format des Floats y um
-// und rundet dabei nötigenfalls.
+// und rundet dabei nötigenfalls.
// > x: ein Integer
// > y: ein Float
// < ergebnis: (float x y)
extern const cl_F cl_float (const cl_I& x, const cl_F& y);
// cl_float(x,y) wandelt ein Integer x in das Float-Format f um
-// und rundet dabei nötigenfalls.
+// und rundet dabei nötigenfalls.
// > x: ein Integer
// > f: eine Float-Format-Spezifikation
// < ergebnis: (float x f)
// cl_float(x) wandelt ein Integer x in ein Float um und rundet dabei.
// > x: ein Integer
// < ergebnis: (float x)
-// Abhängig von default_float_format.
+// Abhängig von default_float_format.
extern const cl_F cl_float (const cl_I& x);
// cl_float(x,y) wandelt eine rationale Zahl x in das Float-Format des
-// Floats y um und rundet dabei nötigenfalls.
+// Floats y um und rundet dabei nötigenfalls.
// > x: eine rationale Zahl
// > y: ein Float
// < ergebnis: (float x y)
extern const cl_F cl_float (const cl_RA& x, const cl_F& y);
// cl_float(x,y) wandelt eine rationale Zahl x in das Float-Format f um
-// und rundet dabei nötigenfalls.
+// und rundet dabei nötigenfalls.
// > x: eine rationale Zahl
// > f: eine Float-Format-Spezifikation
// < ergebnis: (float x f)
// cl_float(x) wandelt eine rationale Zahl x in ein Float um und rundet dabei.
// > x: eine rationale Zahl
// < ergebnis: (float x)
-// Abhängig von default_float_format.
+// Abhängig von default_float_format.
extern const cl_F cl_float (const cl_RA& x);
// The C++ compilers are not clever enough to guess this:
{ return x + cl_float(y,x); }
inline const cl_F operator+ (const cl_F& x, const cl_I& y)
{ return x + cl_float(y,x); }
-// Dem C++-Compiler muß man nun auch das Folgende sagen:
+// Dem C++-Compiler muß man nun auch das Folgende sagen:
inline const cl_F operator+ (const int x, const cl_F& y)
{ return cl_I(x) + y; }
inline const cl_F operator+ (const unsigned int x, const cl_F& y)
{ return cl_I(x) + y; }
inline const cl_F operator+ (const unsigned long x, const cl_F& y)
{ return cl_I(x) + y; }
+#ifdef HAVE_LONGLONG
+inline const cl_F operator+ (const long long x, const cl_F& y)
+ { return cl_I(x) + y; }
+inline const cl_F operator+ (const unsigned long long x, const cl_F& y)
+ { return cl_I(x) + y; }
+#endif
inline const cl_F operator+ (const float x, const cl_F& y)
{ return cl_F(x) + y; }
inline const cl_F operator+ (const double x, const cl_F& y)
{ return x + cl_I(y); }
inline const cl_F operator+ (const cl_F& x, const unsigned long y)
{ return x + cl_I(y); }
+#ifdef HAVE_LONGLONG
+inline const cl_F operator+ (const cl_F& x, const long long y)
+ { return x + cl_I(y); }
+inline const cl_F operator+ (const cl_F& x, const unsigned long long y)
+ { return x + cl_I(y); }
+#endif
inline const cl_F operator+ (const cl_F& x, const float y)
{ return x + cl_F(y); }
inline const cl_F operator+ (const cl_F& x, const double y)
{ return x - cl_float(y,x); }
inline const cl_F operator- (const cl_F& x, const cl_I& y)
{ return x - cl_float(y,x); }
-// Dem C++-Compiler muß man nun auch das Folgende sagen:
+// Dem C++-Compiler muß man nun auch das Folgende sagen:
inline const cl_F operator- (const int x, const cl_F& y)
{ return cl_I(x) - y; }
inline const cl_F operator- (const unsigned int x, const cl_F& y)
{ return cl_I(x) - y; }
inline const cl_F operator- (const unsigned long x, const cl_F& y)
{ return cl_I(x) - y; }
+#ifdef HAVE_LONGLONG
+inline const cl_F operator- (const long long x, const cl_F& y)
+ { return cl_I(x) - y; }
+inline const cl_F operator- (const unsigned long long x, const cl_F& y)
+ { return cl_I(x) - y; }
+#endif
inline const cl_F operator- (const float x, const cl_F& y)
{ return cl_F(x) - y; }
inline const cl_F operator- (const double x, const cl_F& y)
{ return x - cl_I(y); }
inline const cl_F operator- (const cl_F& x, const unsigned long y)
{ return x - cl_I(y); }
+#ifdef HAVE_LONGLONG
+inline const cl_F operator- (const cl_F& x, const long long y)
+ { return x - cl_I(y); }
+inline const cl_F operator- (const cl_F& x, const unsigned long long y)
+ { return x - cl_I(y); }
+#endif
inline const cl_F operator- (const cl_F& x, const float y)
{ return x - cl_F(y); }
inline const cl_F operator- (const cl_F& x, const double y)
extern const cl_R cl_F_RA_mul (const cl_F&, const cl_RA&);
return cl_F_RA_mul(y,x);
}
-// Dem C++-Compiler muß man nun auch das Folgende sagen:
+// Dem C++-Compiler muß man nun auch das Folgende sagen:
inline const cl_R operator* (const int x, const cl_F& y)
{ return cl_I(x) * y; }
inline const cl_R operator* (const unsigned int x, const cl_F& y)
{ return cl_I(x) * y; }
inline const cl_R operator* (const unsigned long x, const cl_F& y)
{ return cl_I(x) * y; }
+#ifdef HAVE_LONGLONG
+inline const cl_R operator* (const long long x, const cl_F& y)
+ { return cl_I(x) * y; }
+inline const cl_R operator* (const unsigned long long x, const cl_F& y)
+ { return cl_I(x) * y; }
+#endif
inline const cl_F operator* (const float x, const cl_F& y)
{ return cl_F(x) * y; }
inline const cl_F operator* (const double x, const cl_F& y)
{ return x * cl_I(y); }
inline const cl_R operator* (const cl_F& x, const unsigned long y)
{ return x * cl_I(y); }
+#ifdef HAVE_LONGLONG
+inline const cl_R operator* (const cl_F& x, const long long y)
+ { return x * cl_I(y); }
+inline const cl_R operator* (const cl_F& x, const unsigned long long y)
+ { return x * cl_I(y); }
+#endif
inline const cl_F operator* (const cl_F& x, const float y)
{ return x * cl_F(y); }
inline const cl_F operator* (const cl_F& x, const double y)
{ return x / cl_I(y); }
inline const cl_F operator/ (const cl_F& x, const unsigned long y)
{ return x / cl_I(y); }
+#ifdef HAVE_LONGLONG
+inline const cl_F operator/ (const cl_F& x, const long long y)
+ { return x / cl_I(y); }
+inline const cl_F operator/ (const cl_F& x, const unsigned long long y)
+ { return x / cl_I(y); }
+#endif
inline const cl_F operator/ (const cl_F& x, const float y)
{ return x / cl_F(y); }
inline const cl_F operator/ (const cl_F& x, const double y)
{ return cl_I(x) / y; }
inline const cl_R operator/ (const unsigned long x, const cl_F& y)
{ return cl_I(x) / y; }
+#ifdef HAVE_LONGLONG
+inline const cl_R operator/ (const long long x, const cl_F& y)
+ { return cl_I(x) / y; }
+inline const cl_R operator/ (const unsigned long long x, const cl_F& y)
+ { return cl_I(x) / y; }
+#endif
inline const cl_F operator/ (const float x, const cl_F& y)
{ return cl_F(x) / y; }
inline const cl_F operator/ (const double x, const cl_F& y)
// Ergebnis: 0 falls x=y, +1 falls x>y, -1 falls x<y.
extern cl_signean compare (const cl_F& x, const cl_F& y);
-// equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
+// equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
extern uint32 equal_hashcode (const cl_F& x);
inline bool operator== (const cl_F& x, const cl_F& y)
// den Exponenten von (decode-float x).
// x = 0.0 liefert 0.
// x = (-1)^s * 2^e * m liefert e.
-extern sintL float_exponent (const cl_F& x);
+extern sintE float_exponent (const cl_F& x);
// float_radix(x) liefert (float-radix x), wo x ein Float ist.
inline sintL float_radix (const cl_F& x)
extern const cl_F zeta (int s);
-// random_F(randomstate,n) liefert zu einem Float n>0 ein zufälliges
+// random_F(randomstate,n) liefert zu einem Float n>0 ein zufälliges
// Float x mit 0 <= x < n.
-// > randomstate: ein Random-State, wird verändert
+// > randomstate: ein Random-State, wird verändert
extern const cl_F random_F (random_state& randomstate, const cl_F& n);
inline const cl_F random_F (const cl_F& n)
inline cl_F& operator/= (cl_F& x, const double y) { return x = x / y; }
#endif
+// Thrown when a floating-point exception occurs.
+class floating_point_exception : public runtime_exception {
+public:
+ explicit floating_point_exception(const std::string & what)
+ : runtime_exception(what) {}
+};
+
+// Thrown when NaN occurs.
+class floating_point_nan_exception : public floating_point_exception {
+public:
+ floating_point_nan_exception();
+};
+
+// Thrown when overflow occurs.
+class floating_point_overflow_exception : public floating_point_exception {
+public:
+ floating_point_overflow_exception();
+};
+
+// Thrown when underflow occurs.
+class floating_point_underflow_exception : public floating_point_exception {
+public:
+ floating_point_underflow_exception();
+};
+
CL_REQUIRE(cl_ieee)
-// If this is true, floating point underflow returns zero instead of an error.
-extern cl_boolean cl_inhibit_floating_point_underflow;
+// If this is true, floating point underflow returns zero instead of throwing an exception.
+extern bool cl_inhibit_floating_point_underflow;
} // namespace cln