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_;