49 #include "clipper_precision.h"
62 typedef union { uitype32 i; ftype32 f; } U32;
63 typedef union { uitype64 i; ftype64 f; } U64;
66 static const ftype&
nan() {
return nan_; }
69 static const float&
nanf() {
return nanf_; }
71 static const double&
nand() {
return nand_; }
73 inline static void set_null( ftype32& f ) { U32*
const u1=(U32*
const)&f;
const U32*
const u2=(
const U32*
const)&nanf_; u1->i = u2->i; }
75 inline static void set_null( ftype64& f ) { U64*
const u1=(U64*
const)&f;
const U64*
const u2=(
const U64*
const)&nand_; u1->i = u2->i; }
77 inline static bool is_null(
const ftype32& f ) { U32 u1,u2; u1.f = f; u2.f = nanf_;
return ( u1.i == u2.i ); }
79 inline static bool is_null(
const ftype64& f ) { U64 u1,u2; u1.f = f; u2.f = nand_;
return ( u1.i == u2.i ); }
82 inline static bool is_nan(
const ftype32 f ) { U32 u; u.f = f;
return ((u.i&CLIPPER_NAN_MASK_A_32)==CLIPPER_NAN_MASK_A_32); }
85 inline static bool is_nan(
const ftype64 f ) { U64 u; u.f = f;
return ((u.i&CLIPPER_NAN_MASK_A_64)==CLIPPER_NAN_MASK_A_64); }
88 inline static bool isnan(
const ftype32 f) { U32 u; u.f = f;
return ((u.i&CLIPPER_NAN_MASK_A_32)==CLIPPER_NAN_MASK_A_32)&&((u.i&CLIPPER_NAN_MASK_B_32)!=0U); }
91 inline static bool isnan(
const ftype64 f) { U64 u; u.f = f;
return ((u.i&CLIPPER_NAN_MASK_A_64)==CLIPPER_NAN_MASK_A_64)&&((u.i&CLIPPER_NAN_MASK_B_64)!=0U); }
111 template<
class T>
inline static T
mean(
const T& pl,
const T& mi )
115 else return 0.5*(pl+mi);
118 template<
class T>
inline static T
sig_mean(
const T& pl,
const T& mi,
const T& cov )
122 else if (
Util::is_nan(cov) )
return 0.5*sqrt(pl*pl+mi*mi);
123 else return 0.5*sqrt(pl*pl+mi*mi+2*cov);
127 inline static int intf(
const ftype& a ) {
return int( floor( a ) ); }
129 inline static int intc(
const ftype& a ) {
return int( ceil( a ) ); }
131 inline static int intr(
const ftype& a ) {
return int( rint( a ) ); }
135 {
ftype c = fmod(a, b);
if (c < 0) c+=b;
return c;}
137 inline static int mod(
const int& a,
const int& b )
138 {
int c = a%b;
if (c < 0) c+=b;
return c; }
140 template<
class T>
inline static T
max(
const T& a,
const T& b)
141 {
return (a > b) ? a : b; }
143 template<
class T>
inline static T
min(
const T& a,
const T& b)
144 {
return (a < b) ? a : b; }
146 template<
class T>
inline static T
bound(
const T&
min,
const T& val,
const T&
max ) {
return ( (val < max) ? ( (val > min ) ? val : min ) : max ); }
148 template<
class T>
inline static void swap( T& a, T& b )
149 { T c = a; a = b; b = c; }
151 template<
class T>
inline static void swap( T& a, T& b, T& c )
152 { c = a; a = b; b = c; }
154 template<
class T>
inline static T
sqr(
const T& a ) {
return a*a; }
156 template<
class T>
inline static T
isqrt(
const T& n )
157 {
return T(floor(sqrt(
ftype(n)))); }
160 inline static const ftype&
pi() {
return onepi_; }
178 static ftype twopi2_;
179 static ftype eightpi2_;
static ftype invsim(const ftype &x)
Inverse Sim function: I1(X)/I0(X)
Definition: clipper_util.cpp:93
static ftype mod(const ftype &a, const ftype &b)
Corrected mod.
Definition: clipper_util.h:134
static const ftype & eightpi2()
8 pi squared
Definition: clipper_util.h:166
static void set_null(ftype64 &f)
set null floating value - a specific value of NaN used for missings
Definition: clipper_util.h:75
static ftype u2b(const ftype &x)
Convert isotropic U-value to B-factor.
Definition: clipper_util.h:107
Utility class.
Definition: clipper_util.h:59
static T min(const T &a, const T &b)
min
Definition: clipper_util.h:143
static T sqr(const T &a)
square
Definition: clipper_util.h:154
Util()
null constructor
Definition: clipper_util.cpp:70
static bool is_null(const ftype32 &f)
fast test for null floating value - only works if set from Util::null()
Definition: clipper_util.h:77
static ftype bessel_i0(const ftype &x)
Modified Bessel function of the first kind.
Definition: clipper_util.cpp:135
static const ftype & twopi()
2 pi
Definition: clipper_util.h:162
static bool is_null(const ftype64 &f)
fast test for null floating value - only works if set from Util::null()
Definition: clipper_util.h:79
static void swap(T &a, T &b, T &c)
swap the contents of two objects, using third as store (for speed)
Definition: clipper_util.h:151
static ftype b2u(const ftype &x)
Convert isotropic B-factor to U-value.
Definition: clipper_util.h:109
static ftype sim(const ftype &x)
Sim function: I1(X)/I0(X)
Definition: clipper_util.cpp:84
static const ftype & nan()
fast Util::nan() value
Definition: clipper_util.h:67
static ftype sim_integ(const ftype &x)
Integral of Sim function: log(I0(X))
Definition: clipper_util.cpp:112
static ftype sim_deriv_recur(const ftype &x)
Derivative of Sim function using recurrance: -sim(x)/x + (1 - sim(x)^2)
Definition: clipper_util.cpp:125
ftype64 ftype
ftype definition for floating point representation
Definition: clipper_precision.h:58
static ftype rad2d(const ftype &x)
degree-to-radian conversion
Definition: clipper_util.cpp:157
static bool isnan(const ftype32 f)
slow general NaN test for compatibility
Definition: clipper_util.h:88
static ftype atanh(const ftype &x)
Arc hyperbolic tangent.
Definition: clipper_util.h:103
static int intf(const ftype &a)
Truncate-to-integer: int(floor(a))
Definition: clipper_util.h:127
static void swap(T &a, T &b)
swap the contents of two objects
Definition: clipper_util.h:148
static int intr(const ftype &a)
Round-to-integer: int(round(a))
Definition: clipper_util.h:131
static T isqrt(const T &n)
Integer square root (returns floor of sqrt)
Definition: clipper_util.h:156
static bool is_nan(const ftype32 f)
fast Util::nan() test
Definition: clipper_util.h:82
static ftype sim_deriv(const ftype &x)
Derivative of Sim function: d/dx( I1(X)/I0(x) )
Definition: clipper_util.cpp:119
static T max(const T &a, const T &b)
max
Definition: clipper_util.h:140
static const double & nand()
fast Util::nan() value
Definition: clipper_util.h:71
static T mean(const T &pl, const T &mi)
Convert F+/F- to mean F, with NaN checks.
Definition: clipper_util.h:111
static bool is_nan(const ftype64 f)
fast Util::nan() test
Definition: clipper_util.h:85
static void set_null(ftype32 &f)
set null floating value - a specific value of NaN used for missings
Definition: clipper_util.h:73
static const ftype & twopi2()
2 pi squared
Definition: clipper_util.h:164
static ftype d2rad(const ftype &x)
degree-to-radian conversion
Definition: clipper_util.cpp:153
static T sig_mean(const T &pl, const T &mi, const T &cov)
Convert sigF+/sigF-/cov to sig F, with NaN checks.
Definition: clipper_util.h:118
static int mod(const int &a, const int &b)
Corrected mod.
Definition: clipper_util.h:137
static bool isnan(const ftype64 f)
slow general NaN test for compatibility
Definition: clipper_util.h:91
static const ftype & pi()
pi
Definition: clipper_util.h:160
static const float & nanf()
fast Util::nan() value
Definition: clipper_util.h:69
static T bound(const T &min, const T &val, const T &max)
bound a value by limits
Definition: clipper_util.h:146
static int intc(const ftype &a)
Truncate-to-integer above: int(ceil(a))
Definition: clipper_util.h:129