#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 cl_F(x) + y; }
inline const cl_F operator+ (const cl_F& x, const int y)
{ return x + cl_I(y); }
inline const cl_F operator+ (const cl_F& x, const unsigned int 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_F(y); }
// Liefert (- x y), wo x und y Floats sind.
extern const cl_F operator- (const cl_F& x, const cl_F& 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 cl_F(x) - y; }
inline const cl_F operator- (const cl_F& x, const int y)
{ return x - cl_I(y); }
inline const cl_F operator- (const cl_F& x, const unsigned int 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_F(y); }
// Liefert (* x y), wo x und y Floats sind.
extern const cl_F operator* (const cl_F& x, const cl_F& 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 cl_F(x) * y; }
inline const cl_R operator* (const cl_F& x, const int y)
{ return x * cl_I(y); }
inline const cl_R operator* (const cl_F& x, const unsigned int 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_F(y); }
// Liefert (* x x), wo x ein Float ist.
extern const cl_F square (const cl_F& x);
{ 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_F(y); }
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 cl_F(x) / y; }
// Liefert (abs x), wo x ein Float ist.
extern const cl_F abs (const cl_F& x);
// 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 float_sign (const cl_F& x, const cl_F& y);
// float_digits(x) liefert (float-digits x), wo x ein Float ist.
-// < ergebnis: ein uintL >0
-extern uintL float_digits (const cl_F& x);
+// < ergebnis: ein uintC >0
+extern uintC float_digits (const cl_F& x);
// float_precision(x) liefert (float-precision x), wo x ein Float ist.
-// < ergebnis: ein uintL >=0
-extern uintL float_precision (const cl_F& x);
+// < ergebnis: ein uintC >=0
+extern uintC float_precision (const cl_F& x);
// Returns the floating point format of a float.
inline float_format_t float_format (const cl_F& x)
// scale_float(x,delta) liefert x*2^delta, wo x ein Float ist.
-extern const cl_F scale_float (const cl_F& x, sintL delta);
+extern const cl_F scale_float (const cl_F& x, sintC delta);
extern const cl_F scale_float (const cl_F& x, const cl_I& delta);
// pi() liefert die Zahl pi im Default-Float-Format.
extern const cl_F pi (void);
-//CL_REQUIRE(cl_F_pi_var)
-
// sin(x) liefert den Sinus (sin x) eines Float x.
extern const cl_F sin (const cl_F& x);
cl_R cos;
cl_R sin;
// Constructor:
+ cos_sin_t () {}
cos_sin_t (const cl_R& u, const cl_R& v) : cos (u), sin (v) {}
};
// exp1() liefert die Zahl e = exp(1) im Default-Float-Format.
extern const cl_F exp1 (void);
-//CL_REQUIRE(cl_F_exp1_var)
-
// ln(x) liefert zu einem Float x>0 die Zahl ln(x).
extern const cl_F ln (const cl_F& x);
cl_R cosh;
cl_R sinh;
// Constructor:
+ cosh_sinh_t () {}
cosh_sinh_t (const cl_R& u, const cl_R& v) : cosh (u), sinh (v) {}
};
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)
{ return random_F(default_random_state,n); }
-#ifdef WANT_OBFUSCATING_OPERATORS
// This could be optimized to use in-place operations.
inline cl_F& operator+= (cl_F& x, const cl_F& y) { return x = x + y; }
+inline cl_F& operator+= (cl_F& x, const float y) { return x = x + y; }
+inline cl_F& operator+= (cl_F& x, const double y) { return x = x + y; }
inline cl_F& operator++ /* prefix */ (cl_F& x) { return x = plus1(x); }
inline void operator++ /* postfix */ (cl_F& x, int dummy) { (void)dummy; x = plus1(x); }
inline cl_F& operator-= (cl_F& x, const cl_F& y) { return x = x - y; }
+inline cl_F& operator-= (cl_F& x, const float y) { return x = x - y; }
+inline cl_F& operator-= (cl_F& x, const double y) { return x = x - y; }
inline cl_F& operator-- /* prefix */ (cl_F& x) { return x = minus1(x); }
inline void operator-- /* postfix */ (cl_F& x, int dummy) { (void)dummy; x = minus1(x); }
inline cl_F& operator*= (cl_F& x, const cl_F& y) { return x = x * y; }
+inline cl_F& operator*= (cl_F& x, const float y) { return x = x * y; }
+inline cl_F& operator*= (cl_F& x, const double y) { return x = x * y; }
inline cl_F& operator/= (cl_F& x, const cl_F& y) { return x = x / y; }
-#endif
+inline cl_F& operator/= (cl_F& x, const float y) { return x = x / y; }
+inline cl_F& operator/= (cl_F& x, const double y) { return x = x / y; }
+
+// 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