Core 1.0
Ia Class Reference

Intervals of two reals. More...

#include <ia.h>

Public Member Functions

 Ia ()
 Empty.
 
 Ia (const double &)
 Creates an interval.
 
 Ia (const double &, const double &)
 Creates an interval.
 
 Ia (const double[], int)
 Create an interval by computing the minimum and maximum values.
 
 Ia (const Ia &, const Ia &)
 Creates an embedding interval.
 
constexpr double & operator[] (int)
 Access interval bounds.
 
constexpr double operator[] (int) const
 Access interval bounds.
 
Ia operator+ () const
 Overloaded.
 
Ia operator- () const
 Overloaded.
 
Iaoperator+= (const Ia &)
 Destructive addition.
 
Iaoperator-= (const Ia &)
 Subtracts two intervals.
 
Ia AngleTwoPi () const
 Caculate the minimal 2 Math::Pi periodic interval.
 
bool operator> (const double &) const
 Compare interval to a real.
 
bool operator< (const double &) const
 Compare interval to a real.
 
bool operator< (const Ia &) const
 Compare two intervals.
 
bool operator> (const Ia &) const
 Compare two intervals.
 
Ia Intersection (const Ia &) const
 Compute the intersection of two intervals.
 
bool Intersect (const Ia &) const
 Check if two intervals intersect.
 
double Length () const
 Compute the length of the interval.
 
double Center () const
 Compute the center of the interval.
 
double Range () const
 Compute the radius r of the interval [-r,r] embedding the interval.
 

Static Public Member Functions

static Ia Lerp (const Ia &, const Ia &, const double &)
 Linear interpolation of two intervals.
 

Static Public Attributes

static const Ia Empty
 Empty interval.
 
static const Ia Null
 Null interval is zero-set.
 
static const Ia Unit
 Unit interval [0,1].
 
static const Ia Infinity
 Infinity interval.
 

Friends

Ia operator+ (const Ia &x, const Ia &y)
 Adds two intervals.
 
Ia operator- (const Ia &x, const Ia &y)
 Subtracts two intervals.
 
Ia operator- (const Ia &x, const double &a)
 Translates (shift left) an interval by a real value.
 
Ia operator+ (const Ia &x, const double &a)
 Translates (shift right) an interval by a real value.
 
Ia operator- (const double &a, const Ia &x)
 Overloaded.
 
Ia operator+ (const double &a, const Ia &x)
 Overloaded.
 
Ia operator* (const Ia &x, const Ia &y)
 Multiplies two intervals.
 
Ia operator/ (const Ia &x, const Ia &y)
 Divides two intervals.
 
Ia operator* (const Ia &x, const double &a)
 Scales a interval by a double.
 
Ia operator* (const double &a, const Ia &x)
 Left multiply, same as scaling.
 
Ia operator/ (const Ia &x, const double &a)
 Left divide by a double, same as scaling.
 
Ia operator/ (const double &a, const Ia &x)
 Divides a real number by an interval.
 
Ia Min (const Ia &x, const Ia &y)
 Computes the minimum of two intervals.
 
Ia Max (const Ia &x, const Ia &y)
 Computes the maximum of two intervals.
 
Ia sqrt (const Ia &x)
 Computes the square root of an interval.
 
Ia sqr (const Ia &x)
 Compute the squared interval.
 
Ia abs (const Ia &x)
 Computes the absolute value of an interval.
 
Ia sin (const Ia &x)
 Computes the sine of an interval.
 
Ia cos (const Ia &x)
 Computes the cosine of an interval.
 
Ia pow (const Ia &x, const double &n)
 Computes the power of an interval.
 
bool operator== (const Ia &x, const Ia &y)
 Compares two intervals.
 
bool operator!= (const Ia &x, const Ia &y)
 Compares two intervals.
 
std::ostream & operator<< (std::ostream &s, const Ia &x)
 Overloaded output-stream operator.
 

Detailed Description

Intervals of two reals.

Most interval arithmetics operators are intensive because of the tests needed to sort the extrema of the resulting interval. Only addition and subtraction need not use tests and, therefore, are efficient.

Several functions have been implemented with the same syntax as for doubles, such as sqrt() and abs().

Constructor & Destructor Documentation

◆ Ia() [1/4]

Ia::Ia ( const double & x)
inlineexplicit

Creates an interval.

The length of the interval is 0.

Parameters
xReal.

◆ Ia() [2/4]

Ia::Ia ( const double & x,
const double & y )
inlineexplicit

Creates an interval.

Parameters
x,yLow and high real values.

◆ Ia() [3/4]

Ia::Ia ( const double v[],
int n )
explicit

Create an interval by computing the minimum and maximum values.

Parameters
vArray.
nSize.

◆ Ia() [4/4]

Ia::Ia ( const Ia & x,
const Ia & y )
inlineexplicit

Creates an embedding interval.

It is the tightest embedding interval.

Parameters
x,yIntervals.

Member Function Documentation

◆ Center()

double Ia::Center ( ) const
inline

Compute the center of the interval.

Same as:

Ia i;
double l=i.Center(); // double l=0.5*(i[1]+i[0]);
Ia()
Empty.
Definition ia.h:12
double Center() const
Compute the center of the interval.
Definition ia.h:254

◆ Intersect()

bool Ia::Intersect ( const Ia & x) const

Check if two intervals intersect.

Parameters
xOther interval.

◆ Intersection()

Ia Ia::Intersection ( const Ia & x) const

Compute the intersection of two intervals.

Parameters
xOther interval.

◆ Length()

double Ia::Length ( ) const
inline

Compute the length of the interval.

Same as:

Ia i;
double l=i.Length(); // double l=i[1]-i[0];
double Length() const
Compute the length of the interval.
Definition ia.h:240

◆ Lerp()

Ia Ia::Lerp ( const Ia & x,
const Ia & y,
const double & t )
static

Linear interpolation of two intervals.

Parameters
x,yIntervals.
tReal.

This code is equivalent but more efficient than an interpolation with overeloaded operators, as coefficients are know to be within unit interval.

const double t=0.25;
Ia z=(1.0-t)*Ia(2.0,3.0)+t*Ia(-1.0,2.0); // Linear interpolation with overloaded operators

◆ operator<() [1/2]

bool Ia::operator< ( const double & x) const

Compare interval to a real.

Check if the entire interval is superior to the real. This is equivalent to:

Ia i;
double x;
if (i[1]<x) {} // if (i<x) {}
Parameters
xReal.

◆ operator<() [2/2]

bool Ia::operator< ( const Ia & y) const

Compare two intervals.

Parameters
yInterval.

◆ operator>() [1/2]

bool Ia::operator> ( const double & x) const

Compare interval to a real.

Check if the entire interval is superior to the real. This is equivalent to:

Ia i;
double x;
if (i[0]>x) {} // if (i>x) {}
Parameters
xReal.

◆ operator>() [2/2]

bool Ia::operator> ( const Ia & y) const

Compare two intervals.

Parameters
yInterval.

◆ Range()

double Ia::Range ( ) const
inline

Compute the radius r of the interval [-r,r] embedding the interval.

Same as:

Ia i;
double l=i.Range(); // double l=Math::Max(fabs(i[0]),fabs(i[1]));
double Range() const
Compute the radius r of the interval [-r,r] embedding the interval.
Definition ia.h:268

Friends And Related Symbol Documentation

◆ abs

Ia abs ( const Ia & x)
friend

Computes the absolute value of an interval.

Parameters
xInterval.

◆ cos

Ia cos ( const Ia & x)
friend

Computes the cosine of an interval.

Parameters
xInterval.

◆ Max

Ia Max ( const Ia & x,
const Ia & y )
friend

Computes the maximum of two intervals.

Parameters
x,yIntervals.

◆ Min

Ia Min ( const Ia & x,
const Ia & y )
friend

Computes the minimum of two intervals.

Parameters
x,yIntervals.

◆ operator!=

bool operator!= ( const Ia & x,
const Ia & y )
friend

Compares two intervals.

Parameters
x,yIntervals.

◆ operator* [1/3]

Ia operator* ( const double & a,
const Ia & x )
friend

Left multiply, same as scaling.

Parameters
xInterval.
aReal.

◆ operator* [2/3]

Ia operator* ( const Ia & x,
const double & a )
friend

Scales a interval by a double.

Parameters
xInterval.
aReal.

◆ operator* [3/3]

Ia operator* ( const Ia & x,
const Ia & y )
friend

Multiplies two intervals.

Parameters
x,yIntervals.

◆ operator+ [1/3]

Ia operator+ ( const double & a,
const Ia & x )
friend

Overloaded.

Parameters
xInterval.
aReal.

◆ operator+ [2/3]

Ia operator+ ( const Ia & x,
const double & a )
friend

Translates (shift right) an interval by a real value.

Parameters
xInterval.
aReal.

◆ operator+ [3/3]

Ia operator+ ( const Ia & x,
const Ia & y )
friend

Adds two intervals.

Parameters
x,yIntervals.

◆ operator- [1/3]

Ia operator- ( const double & a,
const Ia & x )
friend

Overloaded.

Parameters
xInterval.
aReal.

◆ operator- [2/3]

Ia operator- ( const Ia & x,
const double & a )
friend

Translates (shift left) an interval by a real value.

Parameters
xInterval.
aReal.

◆ operator- [3/3]

Ia operator- ( const Ia & x,
const Ia & y )
friend

Subtracts two intervals.

Parameters
x,yIntervals.

◆ operator/ [1/3]

Ia operator/ ( const double & a,
const Ia & x )
friend

Divides a real number by an interval.

Parameters
aReal.
xInterval.

◆ operator/ [2/3]

Ia operator/ ( const Ia & x,
const double & a )
friend

Left divide by a double, same as scaling.

Parameters
xInterval.
aReal.

◆ operator/ [3/3]

Ia operator/ ( const Ia & x,
const Ia & y )
friend

Divides two intervals.

Parameters
x,yIntervals.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Ia & x )
friend

Overloaded output-stream operator.

Parameters
sStream.
xInterval.

◆ operator==

bool operator== ( const Ia & x,
const Ia & y )
friend

Compares two intervals.

Parameters
x,yArgument intervals.

◆ pow

Ia pow ( const Ia & x,
const double & n )
friend

Computes the power of an interval.

Parameters
xInterval.
nPower.

◆ sin

Ia sin ( const Ia & x)
friend

Computes the sine of an interval.

See also
cos(const Ia&)
Parameters
xInterval.

◆ sqr

Ia sqr ( const Ia & x)
friend

Compute the squared interval.

This function is more efficient than multiplication.

Parameters
xInterval.

◆ sqrt

Ia sqrt ( const Ia & x)
friend

Computes the square root of an interval.

Interval should have positive bounds.

Parameters
xInterval.