#ifndef __INTERVAL__
#define __INTERVAL__

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream.h>
#include <iomanip.h>
#include "iboolean.h"

#define oo 1/0.0 //definition de l'infini noté oo
/* #define cos 0
   #define sin 1
   #define sinc 2
   #define tan 3
   #define atan 4  */


typedef double reel;
double Arccossin(const double&,const double&);
double Arg      (const double&,const double&);

class interval
{
public:
    reel inf;
    reel sup;   //sup NE SOIT PAS ACCESSIBLE SI
    bool isEmpty;

public:
    //--------------------------------------------------------------------------
    //                           CONSTRUCTEURS
    //--------------------------------------------------------------------------
    interval ();
    interval (const reel&);    // Pas const pour conversion reel -> interval
    interval (const reel&, const reel&);
    interval (const interval&);
    interval& operator= (const interval&);
    //--------------------------------------------------------------------------
    //                          OPERATEURS
    //--------------------------------------------------------------------------
    friend interval operator+ (const interval&,const interval&);
    friend interval operator- (const interval&);
    friend interval operator- (const interval&, const interval&);
    friend interval operator* (const reel, const interval&);
    friend interval operator* (const interval&, const reel);
    friend interval operator* (const interval&, const interval&);
    friend interval operator/ (const interval& ,const interval&);
    friend ostream& operator<<(ostream& ,const interval&);
    //--------------------------------------------------------------------------
    //                 FONCTION  ET PROCEDURES AMIES
    //--------------------------------------------------------------------------
    friend interval  Abs        (const interval&);
    friend interval  Cos        (const interval&);
    friend interval  Exp        (const interval&);
    friend interval  Inflate    (const interval&,reel);
    friend interval  Inter      (const interval&,const interval&);
    friend interval  InterMin   (const interval&,const interval&,char);
    friend interval  Log        (const interval&);
    friend interval  Max        (const interval&,const interval&);
    friend interval  Min        (const interval&,const interval&);
    friend interval  Parabole   (const interval&, reel, reel, reel);
    friend interval  Power      (const interval&,int);
    friend interval  Pow        (const interval&, int);
    friend interval  Pow        (const interval&, int, int);
    friend interval  PowRoot    (const interval&, int, int);
    friend interval  Sin        (const interval&);
    friend interval  Sqr        (const interval&);
    friend interval  Sqrt       (const interval&);
    friend interval  InvSqrt    (const interval&);
    friend interval  Union      (const interval&, const interval&);
    friend interval  Tan        (const interval&);

    friend iboolean  In         (const interval&,const interval&);

    friend bool      Disjoint   (const interval&,const interval&);
    friend bool      In         (reel,const interval&);
    friend bool      Subset     (const interval&,const interval&);
    friend bool      SubsetStrict(const interval& a,const interval& b);
    friend bool      Subset     (const interval&,const interval&,reel);
    friend bool      OverLap    (const interval&,const interval&);

    friend void      Sucre      (interval&, const interval&);
    friend void      Inter1     (interval&, interval&,const interval&,const interval&, const interval&);

    friend reel      Inf        (const interval&);
    friend reel      Sup        (const interval&);
    friend reel      Rand       (const interval&);
    friend reel      Center     (const interval&);
    friend reel      Eloignement(const interval&, const interval&);
    friend reel      Marge      (const interval&, const interval&);
    friend reel      AbsMax     (const interval&);
    friend reel      ToReel     (const interval&);
    friend reel      Width      (const interval&);
    friend reel      Width2      (const interval&);
    //--------------------------------------------------------------------------
    //    PROCEDURES TRADUISANT LE C.S.P POUR (SIN, COS, PLUS, EXP, ...)
    //--------------------------------------------------------------------------
    //             Contrainte Spécifique
    friend void      Csame_sign(interval&, interval&);
    //            Contraintes Unaires
    friend void      Cinteger    (interval&);
    friend void      Cboolean    (interval&);

    //             Contraintes Binaires
    friend void      Csin    (interval&, interval&, int);
    friend void      Ccos    (interval&, interval&, int);
    friend void      Csinc   (interval&, interval&, int);
    friend void      Cexp    (interval&, interval&, int);
    friend void      Clog    (interval&, interval&, int);
    friend void      Ctan    (interval&, interval&, int);
    friend void      Catan   (interval&, interval&, int);
    friend void      Csqr    (interval&, interval&, int);
    friend void      Csqrt   (interval&, interval&, int);
    friend void      Cmoins  (interval&, interval&, int);
    friend void      Cegal   (interval&, interval&, int);
    friend void      Cegal   (interval&, interval&);
    friend void      Cabs    (interval&, interval&, int);
    friend void      Crect   (interval&, interval&, int);
    friend void      Cpower  (interval&, interval&, int, int);
    friend void      Ctriangle (interval&, interval&, int);
    friend void      Cramp   (interval&, interval&, int, double a=0);
    friend void      Cstep   (interval&, interval&, int, double a=0);
    friend void      Cheaviside (interval&, interval&, int, double a=0);
    friend void      Csign   (interval&, interval&, int, double a=0);
    //              Contraintes Ternaires
    friend void      Crect   (interval&, interval&, interval&, int);
    friend void      Cplus   (interval&, interval&, interval&, int);
    friend void      Cplus   (double&,   interval&, interval&, int);
    friend void      Cmoins  (interval&, interval&, interval&, int);
    friend void      Cmoins   (double&,   interval&, interval&, int);
    friend void      Cmoins  (interval&, interval&, double& x, int);
    friend void      CNorm   (interval&,interval&,interval& );
    friend void      Cprod   (interval&, interval&, interval&, int);
    friend void      Cdiv    (interval&, interval&, interval&, int);
    friend void      Cmin    (interval&, interval&, interval&, int);
    friend void      Cmax    (interval&, interval&, interval&, int);
    friend int      CAngle  (interval&,interval&,interval&,interval&,interval&,bool);

    //------- Procédure de réduction élémentaires sur les intervalles ----------
    friend void      Contract0       (char, interval&, interval&, int, int n=0);
    friend void      Contract0       (char, interval&, interval&, interval&, int);
    friend void      Contract0       (char, interval&, reel&    , interval&, int); //Luc

    friend void      Contract0       (char, interval&);
    //--------------------------------------------------------------------------
    //
    friend void      ShowContraction (interval&, interval&, interval&, interval&);
    friend void      IntButterfly    (interval&, interval, interval, interval&, interval, int);


};
#endif
