/usr/include/cln/dfloat.h is in libcln-dev 1.3.2-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | // Public double float operations.
#ifndef _CL_DFLOAT_H
#define _CL_DFLOAT_H
#include "cln/number.h"
#include "cln/dfloat_class.h"
#include "cln/integer_class.h"
#include "cln/float.h"
namespace cln {
CL_DEFINE_AS_CONVERSION(cl_DF)
// Liefert zu einem Double-Float x : (- x), ein DF.
extern const cl_DF operator- (const cl_DF& x);
// compare(x,y) vergleicht zwei Double-Floats x und y.
// Ergebnis: 0 falls x=y, +1 falls x>y, -1 falls x<y.
extern cl_signean compare (const cl_DF& x, const cl_DF& y);
// equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
extern uint32 equal_hashcode (const cl_DF& x);
inline bool operator== (const cl_DF& x, const cl_DF& y)
{ return compare(x,y)==0; }
inline bool operator!= (const cl_DF& x, const cl_DF& y)
{ return compare(x,y)!=0; }
inline bool operator<= (const cl_DF& x, const cl_DF& y)
{ return compare(x,y)<=0; }
inline bool operator< (const cl_DF& x, const cl_DF& y)
{ return compare(x,y)<0; }
inline bool operator>= (const cl_DF& x, const cl_DF& y)
{ return compare(x,y)>=0; }
inline bool operator> (const cl_DF& x, const cl_DF& y)
{ return compare(x,y)>0; }
// minusp(x) == (< x 0)
extern bool minusp (const cl_DF& x);
// zerop(x) stellt fest, ob ein Double-Float x = 0.0 ist.
extern bool zerop (const cl_DF& x);
// plusp(x) == (> x 0)
extern bool plusp (const cl_DF& x);
// Liefert zu zwei Double-Float x und y : (+ x y), ein DF.
extern const cl_DF operator+ (const cl_DF& x, const cl_DF& y);
// The C++ compiler may hesitate to do these conversions of its own:
inline const cl_DF operator+ (const cl_DF& x, const double y)
{ return x + cl_DF(y); }
inline const cl_DF operator+ (const double x, const cl_DF& y)
{ return cl_DF(x) + y; }
// Liefert zu zwei Double-Float x und y : (- x y), ein DF.
extern const cl_DF operator- (const cl_DF& x, const cl_DF& y);
// The C++ compiler may hesitate to do these conversions of its own:
inline const cl_DF operator- (const cl_DF& x, const double y)
{ return x - cl_DF(y); }
inline const cl_DF operator- (const double x, const cl_DF& y)
{ return cl_DF(x) - y; }
// Liefert zu zwei Double-Float x und y : (* x y), ein DF.
extern const cl_DF operator* (const cl_DF& x, const cl_DF& y);
// The C++ compiler may hesitate to do these conversions of its own:
inline const cl_DF operator* (const cl_DF& x, const double y)
{ return x * cl_DF(y); }
inline const cl_DF operator* (const double x, const cl_DF& y)
{ return cl_DF(x) * y; }
// Liefert zu einem Double-Float x : (* x x), ein DF.
inline const cl_DF square (const cl_DF& x) { return x*x; }
// Liefert zu zwei Double-Float x und y : (/ x y), ein DF.
extern const cl_DF operator/ (const cl_DF& x, const cl_DF& y);
// The C++ compiler may hesitate to do these conversions of its own:
inline const cl_DF operator/ (const cl_DF& x, const double y)
{ return x / cl_DF(y); }
inline const cl_DF operator/ (const double x, const cl_DF& y)
{ return cl_DF(x) / y; }
// Liefert zu einem Double-Float x>=0 : (sqrt x), ein DF.
extern const cl_DF sqrt (const cl_DF& x);
// recip(x) liefert (/ x), wo x ein Double-Float ist.
extern const cl_DF recip (const cl_DF& x);
// abs(x) liefert (abs x), wo x ein Double-Float ist.
extern const cl_DF abs (const cl_DF& x);
// (1+ x), wo x ein Double-Float ist.
inline const cl_DF plus1 (const cl_DF& x)
{
extern const cl_DF cl_I_to_DF (const cl_I&);
return x + cl_I_to_DF(cl_I(1));
}
// (1- x), wo x ein Double-Float ist.
inline const cl_DF minus1 (const cl_DF& x)
{
extern const cl_DF cl_I_to_DF (const cl_I&);
return x + cl_I_to_DF(cl_I(-1));
}
// ffloor(x) liefert (ffloor x), wo x ein DF ist.
extern const cl_DF ffloor (const cl_DF& x);
// fceiling(x) liefert (fceiling x), wo x ein DF ist.
extern const cl_DF fceiling (const cl_DF& x);
// ftruncate(x) liefert (ftruncate x), wo x ein DF ist.
extern const cl_DF ftruncate (const cl_DF& x);
// fround(x) liefert (fround x), wo x ein DF ist.
extern const cl_DF fround (const cl_DF& x);
// Return type for frounding operators.
// x / y --> (q,r) with x = y*q+r.
struct cl_DF_fdiv_t {
cl_DF quotient;
cl_DF remainder;
// Constructor.
cl_DF_fdiv_t () {}
cl_DF_fdiv_t (const cl_DF& q, const cl_DF& r) : quotient(q), remainder(r) {}
};
// ffloor2(x) liefert (ffloor x), wo x ein DF ist.
inline const cl_DF_fdiv_t ffloor2 (const cl_DF& x)
{ cl_DF q = ffloor(x); return cl_DF_fdiv_t(q,x-q); }
// fceiling2(x) liefert (fceiling x), wo x ein DF ist.
inline const cl_DF_fdiv_t fceiling2 (const cl_DF& x)
{ cl_DF q = fceiling(x); return cl_DF_fdiv_t(q,x-q); }
// ftruncate2(x) liefert (ftruncate x), wo x ein DF ist.
inline const cl_DF_fdiv_t ftruncate2 (const cl_DF& x)
{ cl_DF q = ftruncate(x); return cl_DF_fdiv_t(q,x-q); }
// fround2(x) liefert (fround x), wo x ein DF ist.
inline const cl_DF_fdiv_t fround2 (const cl_DF& x)
{ cl_DF q = fround(x); return cl_DF_fdiv_t(q,x-q); }
// Return type for rounding operators.
// x / y --> (q,r) with x = y*q+r.
struct cl_DF_div_t {
cl_I quotient;
cl_DF remainder;
// Constructor.
cl_DF_div_t () {}
cl_DF_div_t (const cl_I& q, const cl_DF& r) : quotient(q), remainder(r) {}
};
// floor2(x) liefert (floor x), wo x ein DF ist.
inline const cl_DF_div_t floor2 (const cl_DF& x)
{
extern const cl_I cl_DF_to_I (const cl_DF& x);
cl_DF q = ffloor(x);
return cl_DF_div_t(cl_DF_to_I(q),x-q);
}
inline const cl_I floor1 (const cl_DF& x)
{
extern const cl_I cl_DF_to_I (const cl_DF& x);
return cl_DF_to_I(ffloor(x));
}
// ceiling2(x) liefert (ceiling x), wo x ein DF ist.
inline const cl_DF_div_t ceiling2 (const cl_DF& x)
{
extern const cl_I cl_DF_to_I (const cl_DF& x);
cl_DF q = fceiling(x);
return cl_DF_div_t(cl_DF_to_I(q),x-q);
}
inline const cl_I ceiling1 (const cl_DF& x)
{
extern const cl_I cl_DF_to_I (const cl_DF& x);
return cl_DF_to_I(fceiling(x));
}
// truncate2(x) liefert (truncate x), wo x ein DF ist.
inline const cl_DF_div_t truncate2 (const cl_DF& x)
{
extern const cl_I cl_DF_to_I (const cl_DF& x);
cl_DF q = ftruncate(x);
return cl_DF_div_t(cl_DF_to_I(q),x-q);
}
inline const cl_I truncate1 (const cl_DF& x)
{
extern const cl_I cl_DF_to_I (const cl_DF& x);
return cl_DF_to_I(ftruncate(x));
}
// round2(x) liefert (round x), wo x ein DF ist.
inline const cl_DF_div_t round2 (const cl_DF& x)
{
extern const cl_I cl_DF_to_I (const cl_DF& x);
cl_DF q = fround(x);
return cl_DF_div_t(cl_DF_to_I(q),x-q);
}
inline const cl_I round1 (const cl_DF& x)
{
extern const cl_I cl_DF_to_I (const cl_DF& x);
return cl_DF_to_I(fround(x));
}
// floor2(x,y) liefert (floor x y).
extern const cl_DF_div_t floor2 (const cl_DF& x, const cl_DF& y);
inline const cl_I floor1 (const cl_DF& x, const cl_DF& y) { return floor1(x/y); }
// ceiling2(x,y) liefert (ceiling x y).
extern const cl_DF_div_t ceiling2 (const cl_DF& x, const cl_DF& y);
inline const cl_I ceiling1 (const cl_DF& x, const cl_DF& y) { return ceiling1(x/y); }
// truncate2(x,y) liefert (truncate x y).
extern const cl_DF_div_t truncate2 (const cl_DF& x, const cl_DF& y);
inline const cl_I truncate1 (const cl_DF& x, const cl_DF& y) { return truncate1(x/y); }
// round2(x,y) liefert (round x y).
extern const cl_DF_div_t round2 (const cl_DF& x, const cl_DF& y);
inline const cl_I round1 (const cl_DF& x, const cl_DF& y) { return round1(x/y); }
// Return type for decode_float:
struct decoded_dfloat {
cl_DF mantissa;
cl_I exponent;
cl_DF sign;
// Constructor.
decoded_dfloat () {}
decoded_dfloat (const cl_DF& m, const cl_I& e, const cl_DF& s) : mantissa(m), exponent(e), sign(s) {}
};
// decode_float(x) liefert zu einem Float x: (decode-float x).
// x = 0.0 liefert (0.0, 0, 1.0).
// x = (-1)^s * 2^e * m liefert ((-1)^0 * 2^0 * m, e als Integer, (-1)^s).
extern const decoded_dfloat decode_float (const cl_DF& x);
// float_exponent(x) liefert zu einem Float x:
// den Exponenten von (decode-float x).
// x = 0.0 liefert 0.
// x = (-1)^s * 2^e * m liefert e.
extern sintE float_exponent (const cl_DF& x);
// float_radix(x) liefert (float-radix x), wo x ein Float ist.
inline sintL float_radix (const cl_DF& x)
{
(void)x; // unused x
return 2;
}
// float_sign(x) liefert (float-sign x), wo x ein Float ist.
extern const cl_DF float_sign (const cl_DF& x);
// float_digits(x) liefert (float-digits x), wo x ein Float ist.
// < ergebnis: ein uintC >0
extern uintC float_digits (const cl_DF& x);
// float_precision(x) liefert (float-precision x), wo x ein Float ist.
// < ergebnis: ein uintC >=0
extern uintC float_precision (const cl_DF& x);
// integer_decode_float(x) liefert zu einem Float x: (integer-decode-float x).
// x = 0.0 liefert (0, 0, 1).
// x = (-1)^s * 2^e * m bei Float-Precision p liefert
// (Mantisse 2^p * m als Integer, e-p als Integer, (-1)^s als Fixnum).
extern const cl_idecoded_float integer_decode_float (const cl_DF& x);
// scale_float(x,delta) liefert x*2^delta, wo x ein DF ist.
extern const cl_DF scale_float (const cl_DF& x, sintC delta);
extern const cl_DF scale_float (const cl_DF& x, const cl_I& delta);
// max(x,y) liefert (max x y), wo x und y Floats sind.
extern const cl_DF max (const cl_DF& x, const cl_DF& y);
// min(x,y) liefert (min x y), wo x und y Floats sind.
extern const cl_DF min (const cl_DF& x, const cl_DF& y);
// signum(x) liefert (signum x), wo x ein Float ist.
extern const cl_DF signum (const cl_DF& x);
// Konversion zu einem C "float".
extern float float_approx (const cl_DF& x);
// Konversion zu einem C "double".
extern double double_approx (const cl_DF& x);
// This could be optimized to use in-place operations.
inline cl_DF& operator+= (cl_DF& x, const cl_DF& y) { return x = x + y; }
inline cl_DF& operator+= (cl_DF& x, const double y) { return x = x + y; }
inline cl_DF& operator++ /* prefix */ (cl_DF& x) { return x = plus1(x); }
inline void operator++ /* postfix */ (cl_DF& x, int dummy) { (void)dummy; x = plus1(x); }
inline cl_DF& operator-= (cl_DF& x, const cl_DF& y) { return x = x - y; }
inline cl_DF& operator-= (cl_DF& x, const double y) { return x = x - y; }
inline cl_DF& operator-- /* prefix */ (cl_DF& x) { return x = minus1(x); }
inline void operator-- /* postfix */ (cl_DF& x, int dummy) { (void)dummy; x = minus1(x); }
inline cl_DF& operator*= (cl_DF& x, const cl_DF& y) { return x = x * y; }
inline cl_DF& operator*= (cl_DF& x, const double y) { return x = x * y; }
inline cl_DF& operator/= (cl_DF& x, const cl_DF& y) { return x = x / y; }
inline cl_DF& operator/= (cl_DF& x, const double y) { return x = x / y; }
/* */
// Runtime typing support.
extern cl_class cl_class_dfloat;
// Debugging support.
#ifdef CL_DEBUG
extern int cl_DF_debug_module;
CL_FORCE_LINK(cl_DF_debug_dummy, cl_DF_debug_module)
#endif
} // namespace cln
#endif /* _CL_DFLOAT_H */
|