Core 1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
Ia Class Reference

Intervals of two reals. More...

#include <ia.h>

Public Member Functions

 Ia ()
 Empty.
 
 Ia (const double &)
 Creates an interval. More...
 
 Ia (const double &, const double &)
 Creates an interval. More...
 
 Ia (const Ia &, const Ia &)
 Creates an interval. More...
 
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.
 
bool operator> (const double &) const
 Compare interval to a real. More...
 
bool operator< (const double &) const
 Compare interval to a real. More...
 
bool operator< (const Ia &) const
 Compare two intervals. More...
 
bool operator> (const Ia &) const
 Compare two intervals. More...
 
Ia Intersection (const Ia &) const
 Compute the intersection of two intervals. More...
 
bool Intersect (const Ia &) const
 Check if two intervals intersect. More...
 
double Length () const
 Compute the length of the interval. More...
 

Static Public Member Functions

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

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

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/3]

Ia::Ia ( const double &  a)
inlineexplicit

Creates an interval.

The length of the interval is 0.

Parameters
aReal.

◆ Ia() [2/3]

Ia::Ia ( const double &  a,
const double &  b 
)
inlineexplicit

Creates an interval.

Parameters
a,bLow and high real values.

◆ Ia() [3/3]

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

Creates an interval.

It is the tightest embedding interval.

Parameters
x,yIntervals.

Member Function Documentation

◆ 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];
Intervals of two reals.
Definition: ia.h:8
double Length() const
Compute the length of the interval.
Definition: ia.h:239

◆ 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
Ia()
Empty.
Definition: ia.h:13

◆ 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 y;
if (i[1]<x) {} // if (x<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.

Friends And Related Function Documentation

◆ abs

Ia abs ( const Ia x)
friend

Computes the absolute value 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.

Check whether the scaling term is infinity or 0.0 to speed up interval computation.

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.

◆ 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.