val.hpp /usr/include/gecode/float.hh Gecode Gecode::Float /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *VincentBarichard<Vincent.Barichard@univ-angers.fr> * *Contributingauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2012 *VincentBarichard,2012 * *Lastmodified: *$Date:2013-01-2917:43:05+0100(Tue,29Jan2013)$by$Author:schulte$ *$Revision:13241$ * *ThisfileispartofGecode,thegenericconstraint *developmentenvironment: *http://www.gecode.org * *Permissionisherebygranted,freeofcharge,toanypersonobtaining *acopyofthissoftwareandassociateddocumentationfiles(the *"Software"),todealintheSoftwarewithoutrestriction,including *withoutlimitationtherightstouse,copy,modify,merge,publish, *distribute,sublicense,and/orsellcopiesoftheSoftware,andto *permitpersonstowhomtheSoftwareisfurnishedtodoso,subjectto *thefollowingconditions: * *Theabovecopyrightnoticeandthispermissionnoticeshallbe *includedinallcopiesorsubstantialportionsoftheSoftware. * *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, *EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF *MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEAND *NONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBE *LIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTION *OFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTION *WITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE. * */ namespaceGecode{ /* *Floatingpointvalue:memberfunctions * */ forceinline FloatVal::FloatVal(void){} forceinline FloatVal::FloatVal(constFloatNum&n):x(n){} forceinline FloatVal::FloatVal(constFloatNum&l,constFloatNum&u):x(l,u){} forceinline FloatVal::FloatVal(constFloatValImpType&i):x(i){} forceinline FloatVal::FloatVal(constFloatVal&v):x(v.x){} forceinlineFloatVal& FloatVal::operator =(constFloatNum&n){ x=n;return*this; } forceinlineFloatVal& FloatVal::operator =(constFloatVal&v){ x=v.x;return*this; } forceinlinevoid FloatVal::assign(FloatNumconst&l,FloatNumconst&u){ x.assign(l,u); } forceinlineFloatNum FloatVal::min(void)const{ returnx.lower(); } forceinlineFloatNum FloatVal::max(void)const{ returnx.upper(); } forceinlineFloatNum FloatVal::size(void)const{ returnboost::numeric::width(x); } forceinlineFloatNum FloatVal::med(void)const{ returnboost::numeric::median(x); } forceinlinebool FloatVal::tight(void)const{ return(boost::numeric::singleton(x)|| (nextafter(x.lower(),x.upper())==x.upper())); } forceinlinebool FloatVal::singleton(void)const{ returnboost::numeric::singleton(x); } forceinlinebool FloatVal::in(FloatNumn)const{ returnboost::numeric::in(n,x); } forceinlinebool FloatVal::zero_in(void)const{ returnboost::numeric::zero_in(x); } forceinlineFloatVal FloatVal::hull(FloatNumx,FloatNumy){ FloatValh(FloatVal::hull(x,y));returnh; } forceinlineFloatVal FloatVal::pi_half(void){ FloatValp(boost::numeric::interval_lib::pi_half<FloatValImpType>()); returnp; } forceinlineFloatVal FloatVal::pi(void){ FloatValp(boost::numeric::interval_lib::pi<FloatValImpType>()); returnp; } forceinlineFloatVal FloatVal::pi_twice(void){ FloatValp(boost::numeric::interval_lib::pi_twice<FloatValImpType>()); returnp; } forceinlineFloatVal& FloatVal::operator +=(constFloatNum&n){ x+=n;return*this; } forceinlineFloatVal& FloatVal::operator -=(constFloatNum&n){ x-=n;return*this; } forceinlineFloatVal& FloatVal::operator *=(constFloatNum&n){ x*=n;return*this; } forceinlineFloatVal& FloatVal::operator /=(constFloatNum&n){ x/=n;return*this; } forceinlineFloatVal& FloatVal::operator +=(constFloatVal&v){ x+=v.x;return*this; } forceinlineFloatVal& FloatVal::operator -=(constFloatVal&v){ x-=v.x;return*this; } forceinlineFloatVal& FloatVal::operator *=(constFloatVal&v){ x*=v.x;return*this; } forceinlineFloatVal& FloatVal::operator /=(constFloatVal&v){ x/=v.x;return*this; } /* *Operatorsandfunctionsonfloatvalues * */ forceinlineFloatVal operator+(constFloatVal&x){ returnFloatVal(+x.x); } forceinlineFloatVal operator-(constFloatVal&x){ FloatNummmi=(x.min()==0.0)?0.0:-x.min(); FloatNummma=(x.max()==0.0)?0.0:-x.max(); returnFloatVal(mma,mmi); } forceinlineFloatVal operator+(constFloatVal&x,constFloatVal&y){ returnFloatVal(x.x+y.x); } forceinlineFloatVal operator+(constFloatVal&x,constFloatNum&y){ returnFloatVal(x.x+y); } forceinlineFloatVal operator+(constFloatNum&x,constFloatVal&y){ returnFloatVal(x+y.x); } forceinlineFloatVal operator-(constFloatVal&x,constFloatVal&y){ returnFloatVal(x.x-y.x); } forceinlineFloatVal operator-(constFloatVal&x,constFloatNum&y){ returnFloatVal(x.x-y); } forceinlineFloatVal operator-(constFloatNum&x,constFloatVal&y){ returnFloatVal(x-y.x); } forceinlineFloatVal operator*(constFloatVal&x,constFloatVal&y){ returnFloatVal(x.x*y.x); } forceinlineFloatVal operator*(constFloatVal&x,constFloatNum&y){ returnFloatVal(x.x*y); } forceinlineFloatVal operator*(constFloatNum&x,constFloatVal&y){ returnFloatVal(x*y.x); } forceinlineFloatVal operator/(constFloatVal&x,constFloatVal&y){ returnFloatVal(x.x/y.x); } forceinlineFloatVal operator/(constFloatVal&x,constFloatNum&y){ returnFloatVal(x.x/y); } forceinlineFloatVal operator/(constFloatNum&x,constFloatVal&y){ returnFloatVal(x/y.x); } forceinlinebool operator<(constFloatVal&x,constFloatVal&y){ try{ returnx.x<y.x; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator<(constFloatVal&x,constFloatNum&y){ try{ returnx.x<y; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator<=(constFloatVal&x,constFloatVal&y){ try{ returnx.x<=y.x; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator<=(constFloatVal&x,constFloatNum&y){ try{ returnx.x<=y; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator>(constFloatVal&x,constFloatVal&y){ try{ returnx.x>y.x; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator>(constFloatVal&x,constFloatNum&y){ try{ returnx.x>y; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator>=(constFloatVal&x,constFloatVal&y){ try{ returnx.x>=y.x; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator>=(constFloatVal&x,constFloatNum&y){ try{ returnx.x>=y; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator==(constFloatVal&x,constFloatVal&y){ try{ returnx.x==y.x; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator==(constFloatVal&x,constFloatNum&y){ if(!boost::numeric::interval_lib::checking_strict<FloatNum> ::is_empty(x.x.lower(),x.x.upper())){ if((x.x.lower()==y)&&(x.x.upper()==y)) returntrue; } if(((x.x.lower()==y)&& (nextafter(x.x.lower(),x.x.upper())==x.x.upper()))|| ((x.x.upper()==y)&& (nextafter(x.x.upper(),x.x.lower())==x.x.lower()))) returntrue; returnfalse; } forceinlinebool operator!=(constFloatVal&x,constFloatVal&y){ try{ returnx.x!=y.x; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator!=(constFloatVal&x,constFloatNum&y){ try{ returnx.x!=y; }catch(boost::numeric::interval_lib::comparison_error&){ returnfalse; } } forceinlinebool operator<(constFloatNum&x,constFloatVal&y){ returny>x; } forceinlinebool operator<=(constFloatNum&x,constFloatVal&y){ returny>=x; } forceinlinebool operator>(constFloatNum&x,constFloatVal&y){ returny<x; } forceinlinebool operator>=(constFloatNum&x,constFloatVal&y){ returny<=x; } forceinlinebool operator==(constFloatNum&x,constFloatVal&y){ returny==x; } forceinlinebool operator!=(constFloatNum&x,constFloatVal&y){ returny!=x; } template<classChar,classTraits> std::basic_ostream<Char,Traits>& operator<<(std::basic_ostream<Char,Traits>&os,constFloatVal&x){ returnos<<x.x; } forceinlineFloatVal abs(constFloatVal&x){ returnFloatVal(abs(x.x)); } forceinlineFloatVal sqrt(constFloatVal&x){ returnFloatVal(sqrt(x.x)); } forceinlineFloatVal sqr(constFloatVal&x){ returnFloatVal(square(x.x)); } forceinlineFloatVal pow(constFloatVal&x,intn){ returnFloatVal(pow(x.x,n)); } forceinlineFloatVal nroot(constFloatVal&x,intn){ returnFloatVal(nth_root(x.x,n)); } forceinlineFloatVal max(constFloatVal&x,constFloatVal&y){ returnFloatVal(max(x.x,y.x)); } forceinlineFloatVal max(constFloatVal&x,constFloatNum&y){ returnFloatVal(max(x.x,y)); } forceinlineFloatVal max(constFloatNum&x,constFloatVal&y){ returnFloatVal(max(x,y.x)); } forceinlineFloatVal min(constFloatVal&x,constFloatVal&y){ returnFloatVal(min(x.x,y.x)); } forceinlineFloatVal min(constFloatVal&x,constFloatNum&y){ returnFloatVal(min(x.x,y)); } forceinlineFloatVal min(constFloatNum&x,constFloatVal&y){ returnFloatVal(min(x,y.x)); } #ifdefGECODE_HAS_MPFR forceinlineFloatVal exp(constFloatVal&x){ returnFloatVal(exp(x.x)); } forceinlineFloatVal log(constFloatVal&x){ returnFloatVal(log(x.x)); } forceinlineFloatVal fmod(constFloatVal&x,constFloatVal&y){ returnFloatVal(fmod(x.x,y.x)); } forceinlineFloatVal fmod(constFloatVal&x,constFloatNum&y){ returnFloatVal(fmod(x.x,y)); } forceinlineFloatVal fmod(constFloatNum&x,constFloatVal&y){ returnFloatVal(fmod(x,y.x)); } forceinlineFloatVal sin(constFloatVal&x){ returnFloatVal(sin(x.x)); } forceinlineFloatVal cos(constFloatVal&x){ returnFloatVal(cos(x.x)); } forceinlineFloatVal tan(constFloatVal&x){ returnFloatVal(tan(x.x)); } forceinlineFloatVal asin(constFloatVal&x){ returnFloatVal(asin(x.x)); } forceinlineFloatVal acos(constFloatVal&x){ returnFloatVal(acos(x.x)); } forceinlineFloatVal atan(constFloatVal&x){ returnFloatVal(atan(x.x)); } forceinlineFloatVal sinh(constFloatVal&x){ returnFloatVal(sinh(x.x)); } forceinlineFloatVal cosh(constFloatVal&x){ returnFloatVal(cosh(x.x)); } forceinlineFloatVal tanh(constFloatVal&x){ returnFloatVal(tanh(x.x)); } forceinlineFloatVal asinh(constFloatVal&x){ returnFloatVal(asinh(x.x)); } forceinlineFloatVal acosh(constFloatVal&x){ returnFloatVal(acosh(x.x)); } forceinlineFloatVal atanh(constFloatVal&x){ returnFloatVal(atanh(x.x)); } #endif } namespaceGecode{namespaceFloat{ forceinlinebool subset(constFloatVal&x,constFloatVal&y){ returnsubset(x.x,y.x); } forceinlinebool proper_subset(constFloatVal&x,constFloatVal&y){ returnproper_subset(x.x,y.x); } forceinlinebool overlap(constFloatVal&x,constFloatVal&y){ returnoverlap(x.x,y.x); } forceinlineFloatVal intersect(constFloatVal&x,constFloatVal&y){ returnFloatVal(intersect(x.x,y.x)); } forceinlineFloatVal hull(constFloatVal&x,constFloatVal&y){ returnFloatVal(hull(x.x,y.x)); } forceinlineFloatVal hull(constFloatVal&x,constFloatNum&y){ returnFloatVal(hull(x.x,y)); } forceinlineFloatVal hull(constFloatNum&x,constFloatVal&y){ returnFloatVal(hull(x,y.x)); } forceinlineFloatVal hull(constFloatNum&x,constFloatNum&y){ returnFloatVal(hull(x,y)); } }} //STATISTICS:float-var