diff --git a/package.json b/package.json index b1b10a2..bf39435 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "clean": "rm -rf dist lib lib-esm", "deploy": "npm run docs", "docs": "npm run docs:generate && npm run docs:deploy", - "docs:generate": "typedoc --out dist/docs --target es6 --theme minimal src", + "docs:generate": "typedoc --out dist/docs --exclude \"**/?(*.)+(test).ts\" --target es6 --theme minimal src", "docs:deploy": "touch dist/docs/.nojekyll && gh-pages --dotfiles -d dist/docs", "test": "jest --coverage --no-cache", "codecov": "npm run istanbul && codecov < coverage/lcov.info", diff --git a/src/constants.ts b/src/constants.ts index d55297f..0c1f1d5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -31,7 +31,9 @@ const constants = { * @memberof constants * @static * @example + * ```typescript * Interval(Interval.PI_LOW, Interval.PI_HIGH) + * ``` * @name PI * @type {Interval} */ diff --git a/src/interval.ts b/src/interval.ts index fa826c8..06e89e4 100644 --- a/src/interval.ts +++ b/src/interval.ts @@ -16,36 +16,29 @@ import round from './round' * @mixes utils * @mixes constants * - * @see #bounded - * @see #boundedSingleton + * @link #bounded + * @link #boundedSingleton * * @example + * ```typescript * new Interval(1, 2) // {lo: 1, hi: 2} - * @example * // function invocation without new is also supported * Interval(1, 2) // {lo: 1, hi: 2} - * @example * // with numbers * Interval(1, 2) // {lo: 1, hi: 2} * Interval(1) // {lo: 1, hi: 1} - * @example * // with an array * Interval([1, 2]) // {lo: 1, hi: 2} - * @example * // singleton intervals * var x = Interval(1) * var y = Interval(2) * Interval(x, y) // {lo: 1, hi: 2} - * @example * // when `lo > hi` it returns an empty interval * Interval(2, 1) // {lo: Infinity, hi: -Infinity} - * @example * // bounded interval * Interval().bounded(1, 2) // { lo: 0.9999999999999999, hi: 2.0000000000000004 } - * @example * // singleton bounded interval * Interval().boundedSingleton(2) // {lo: 1.9999999999999998, hi: 2.0000000000000004} - * @example * // half open and open intervals * // [2, 3] * Interval(2, 3) // {lo: 2, hi: 3} @@ -55,6 +48,7 @@ import round from './round' * Interval().halfOpenRight(2, 3) // {lo: 2, hi: 2.9999999999999996} * // (2, 3) * Interval().open(2, 3) // {lo: 2.0000000000000004, hi: 2.9999999999999996} + * ``` * * @param {number|array|Interval} lo The left endpoint of the interval if it's a * number or a singleton interval, if it's an array then an interval will be @@ -131,11 +125,16 @@ export class Interval { * previous IEEE floating point value of `lo` and the right endpoint * is equal to the next IEEE floating point * value of `hi`, it's assumed that `lo <= hi` + * * @example - * var x = Interval().bounded(1, 2) + * ```typescript + * const x = Interval().bounded(1, 2) * x.lo < 1 // true, x.lo === 0.9999999999999999 * x.hi > 2 // true, x.hi === 2.0000000000000004 + * ``` + * * @example + * ```typescript * // the correct representation of 1/3 * var x = Interval().bounded(1/3, 1/3) * x.lo < 1/3 // true @@ -145,6 +144,8 @@ export class Interval { * var next = Interval.round.safeNext * var x = Interval().set(1/3, next(1/3)) * // x now represents 1/3 correctly + * ``` + * * @param {number} lo * @param {number} hi * @return {Interval} The calling interval i.e. `this` @@ -219,8 +220,11 @@ export class Interval { * NOTE: `Interval.round.disable` has no effect on this method * * @example + * ```typescript * // (2, 3) * Interval().open(2, 3) // {lo: 2.0000000000000004, hi: 2.9999999999999996} + * ``` + * * @param {number} lo * @param {number} hi * @return {Interval} The calling interval @@ -235,8 +239,11 @@ export class Interval { * NOTE: `Interval.round.disable` has no effect on this method * * @example + * ```typescript * // (2, 3] * Interval().halfOpenLeft(2, 3) // {lo: 2.0000000000000004, hi: 3} + * ``` + * * @param {number} lo * @param {number} hi * @return {Interval} The calling interval @@ -251,8 +258,11 @@ export class Interval { * NOTE: `Interval.round.disable` has no effect on this method * * @example + * ```typescript * // [2, 3) * Interval.halfOpenRight(2, 3) // {lo: 2, hi: 2.9999999999999996} + * ``` + * * @param {number} lo * @param {number} hi * @return {Interval} The calling interval @@ -274,8 +284,10 @@ export class Interval { * @see Interval.clone * @name Interval.prototype * @example + * ```typescript * var x = Interval(2, 3) * x.clone() // Interval(2, 3) + * ``` * @return {Interval} */ clone(): Interval { diff --git a/src/operations/algebra.ts b/src/operations/algebra.ts index 607db31..68a205a 100644 --- a/src/operations/algebra.ts +++ b/src/operations/algebra.ts @@ -12,19 +12,20 @@ import isSafeInteger from 'is-safe-integer' */ /** - * Computes x mod y (x - k * y) + * Computes `x mod y (x - k * y)` + * * @example + * ```typescript * Interval.fmod( * Interval(5.3, 5.3), * Interval(2, 2) * ) // Interval(1.3, 1.3) - * - * @example * Interval.fmod( * Interval(5, 7), * Interval(2, 3) * ) // Interval(2, 5) * // explanation: [5, 7] - [2, 3] * 1 = [2, 5] + * ``` * * @param {Interval} x * @param {Interval} y @@ -43,16 +44,18 @@ export function fmod(x: Interval, y: Interval): Interval { } /** - * Computes 1 / x + * Computes `1 / x` * * @example + * ```typescript * Interval.multiplicativeInverse( * Interval(2, 6) * ) // Interval(1/6, 1/2) - * @example * Interval.multiplicativeInverse( * Interval(-6, -2) * ) // Interval(-1/2, -1/6) + * ``` + * * @param {Interval} x * @returns {Interval} */ @@ -85,37 +88,37 @@ export function multiplicativeInverse(x: Interval): Interval { } /** - * Computes x^power given that `power` is an integer + * Computes `x^power` given that `power` is an integer * - * If `power` is an Interval it must be a singletonInterval i.e. x^x is not + * If `power` is an Interval it must be a singletonInterval i.e. `x^x` is not * supported yet * * If `power` is a rational number use {@link nthRoot} instead * * @example + * ```typescript * // 2^{-2} * Interval.pow( * Interval(2, 2), * -2 * ) // Interval(1/4, 1/4) - * @example * // [2,3]^2 * Interval.pow( * Interval(2, 3), * 2 * ) // Interval(4, 9) - * @example * // [2,3]^0 * Interval.pow( * Interval(2, 3), * 0 * ) // Interval(1, 1) - * @example * // with a singleton interval * Interval.pow( * Interval(2, 3), * Interval(2) * ) // Interval(4, 9) + * ``` + * * @param {Interval} x * @param {number|Interval} power A number of a singleton interval * @returns {Interval} @@ -180,11 +183,15 @@ export function pow(x: Interval, power: Interval | number): Interval { } /** - * Computes sqrt(x), alias for `nthRoot(x, 2)` + * Computes `sqrt(x)`, alias for `nthRoot(x, 2)` + * * @example + * ```typescript * Interval.sqrt( * Interval(4, 9) * ) // Interval(prev(2), next(3)) + * ``` + * * @param {Interval} x * @returns {Interval} */ @@ -193,13 +200,16 @@ export function sqrt(x: Interval): Interval { } /** - * Computes x^(1/n) + * Computes `x^(1/n)` * * @example + * ```typescript * Interval.nthRoot( * Interval(-27, -8), * 3 * ) // Interval(-3, -2) + * ``` + * * @param {Interval} x * @param {number|Interval} n A number or a singleton interval * @return {Interval} diff --git a/src/operations/arithmetic.ts b/src/operations/arithmetic.ts index df3f9fa..022300c 100644 --- a/src/operations/arithmetic.ts +++ b/src/operations/arithmetic.ts @@ -10,11 +10,15 @@ import * as division from './division' /** * Adds two intervals + * * @example + * ```typescript * Interval.add( * Interval(0, 1), * Interval(1, 2), * ) // Interval(prev(1), next(3)) + * ``` + * * @param {Interval} x * @param {Interval} y * @return {Interval} @@ -25,11 +29,15 @@ export function add(x: Interval, y: Interval): Interval { /** * Subtracts two intervals + * * @example + * ```typescript * Interval.subtract( * Interval(0, 1), * Interval(1, 2), * ) // Interval(prev(-2), next(0)) + * ``` + * * @param {Interval} x * @param {Interval} y * @return {Interval} @@ -47,31 +55,47 @@ export const sub = subtract /** * Multiplies two intervals, an explanation of all the possible cases ca * be found on [Interval Arithmetic: from Principles to Implementation - T. Hickey, Q. Ju, M.H. van Emden](http://fab.cba.mit.edu/classes/S62.12/docs/Hickey_interval.pdf) + * * @example + * ```typescript * Interval.multiply( * Interval(1, 2), * Interval(2, 3) * ) // Interval(prev(2), next(6)) + * ``` + * * @example + * ```typescript * Interval.multiply( * Interval(1, Infinity), * Interval(4, 6) * ) // Interval(prev(4), Infinity) + * ``` + * * @example + * ```typescript * Interval.multiply( * Interval(1, 2), * Interval(-3, -2) * ) // Interval(prev(-6), next(-2)) + * ``` + * * @example + * ```typescript * Interval.multiply( * Interval(1, 2), * Interval(-2, 3) * ) // Interval(prev(-4), next(6)) + * ``` + * * @example + * ```typescript * Interval.multiply( * Interval(-2, -1), * Interval(-3, -2) * ) // Interval(prev(2), next(6)) + * ``` + * * @param {Interval} x * @param {Interval} y * @return {Interval} @@ -180,20 +204,29 @@ export const mul = multiply * Boost implements it too) * * @example + * ```typescript * Interval.divide( * Interval(1, 2), * Interval(3, 4) * ) // Interval(prev(1/4), next(2/3)) + * ``` + * * @example + * ```typescript * Interval.divide( * Interval(-2, 1), * Interval(-4, -3) * ) // Interval(prev(-1/3), next(2/3)) + * ``` + * * @example + * ```typescript * Interval.divide( * Interval(1, 2), * Interval(-1, 1) * ) // Interval(-Infinity, Infinity) + * ``` + * * @param {Interval} x * @param {Interval} y * @return {Interval} @@ -229,11 +262,15 @@ export const div = divide /** * Computes +x (identity function) - * @see misc.clone + * @link clone + * * @example + * ```typescript * Interval.positive( * Interval(1, 2) * ) // Interval(1, 2) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -243,18 +280,28 @@ export function positive(x: Interval): Interval { /** * Computes -x + * * @example + * ```typescript * Interval.negative( * Interval(1, 2) * ) // Interval(-2, -1) + * ``` + * * @example + * ```typescript * Interval.negative( * Interval(-Infinity, Infinity) * ) // Interval(-Infinity, Infinity) + * ``` + * * @example + * ```typescript * Interval.negative( * Interval.WHOLE * ) // Interval.WHOLE + * ``` + * * @param {Interval} x * @return {Interval} */ diff --git a/src/operations/misc.ts b/src/operations/misc.ts index aa68ed1..149cb9a 100644 --- a/src/operations/misc.ts +++ b/src/operations/misc.ts @@ -11,10 +11,14 @@ import * as arithmetic from './arithmetic' /** * Computes e^x where e is the mathematical constant equal to the base of the * natural logarithm + * * @example + * ```typescript * Interval.exp( * Interval(-1, 1) * ) // Interval(0.3679, 2.7183) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -27,10 +31,14 @@ export function exp(x: Interval): Interval { /** * Computes the natural logarithm of x + * * @example + * ```typescript * Interval.log( * Interval(1, Math.exp(3)) * ) // Interval(0, 3) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -52,10 +60,14 @@ export const LOG_EXP_10 = log(new Interval(10, 10)) /** * Computes the logarithm base 10 of x + * * @example + * ```typescript * Interval.log10( * Interva(1, 1000) * ) // Interval(0, 3) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -70,10 +82,14 @@ export const LOG_EXP_2 = log(new Interval(2, 2)) /** * Computes the logarithm base 2 of x + * * @example + * ```typescript * Interval.log10( * Interva(1, 8) * ) // Interval(0, 3) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -90,15 +106,17 @@ export function log2(x: Interval): Interval { * interval that represents the hull * * @example + * ```typescript * Interval.hull( * Interval(-1, 1), * Interval(5, 7) * ) // Interval(-1, 7) - * @example * Interval.hull( * Interval(-1, 1), * Interval.EMPTY * ) // Interval(-1, 1) + * ``` + * * @param {Interval} x * @param {Interval} y * @return {Interval} @@ -121,10 +139,13 @@ export function hull(x: Interval, y: Interval): Interval { * Computes an interval that has all the values that belong to both x and y * * @example + * ```typescript * Interval.intersection( * Interval(-1, 1), * Interval(0, 7) * ) // Interval(0, 1) + * ``` + * * @param {Interval} x * @param {Interval} y * @return {Interval} @@ -145,16 +166,19 @@ export function intersection(x: Interval, y: Interval): Interval { * Computes an interval that has all the values that belong to both x and y, * the difference with {@link hull} is that x and y must overlap to * compute the union + * * @example + * ```typescript * Interval.union( * Interval(-1, 1), * Interval(5, 7) * ) // throws error - * @example * Interval.union( * Interval(-1, 1), * Interval(1, 7) * ) // Interval(-1, 7) + * ``` + * * @throws {Error} When x and y don't overlap * @param {Interval} x * @param {Interval} y @@ -170,26 +194,27 @@ export function union(x: Interval, y: Interval): Interval { /** * Computes the difference between `x` and `y`, i.e. an interval with all the * values of `x` that are not in `y` + * * @example + * ```typescript * Interval.difference( * Interval(3, 5), * Interval(4, 6) * ) // Interval(3, prev(4)) - * @example * Interval.difference( * Interval(0, 3), * Interval(0, 1) * ) // Interval(next(1), 3) - * @example * Interval.difference( * Interval(0, 1), * Interval.WHOLE * ) // Interval.EMPTY - * @example * Interval.difference( * Interval(-Infinity, 0), * Interval.WHOLE * ) // Interval.EMPTY + * ``` + * * @throws {Error} When the difference creates multiple intervals * @param {Interval} x * @param {Interval} y @@ -227,24 +252,24 @@ export function difference(x: Interval, y: Interval): Interval { } /** - * Computes the distance between the endpoints of the interval i.e. - * `x.hi - x.lo` + * Computes the distance between the endpoints of the interval i.e. `x.hi - x.lo` + * * @example + * ```typescript * Interval.width( * Interval(1, 2) * ) // 1 - * @example * Interval.width( * Interval(-1, 1) * ) // 2 - * @example * Interval.width( * Interval(1, 1) * ) // next(0) ~5e-324 - * @example * Interval.width( * Interval.EMPTY * ) // 0 + * ``` + * * @param {Interval} x * @returns {number} */ @@ -263,22 +288,23 @@ export const wid = width /** * Computes the absolute value of `x` + * * @example + * ```typescript * Interval.abs( * Interval(2, 3) * ) // Interval(2, 3) - * @example * Interval.abs( * Interval(-2, 3) * ) // Interval(2, 3) - * @example * Interval.abs( * Interval(-3, -2) * ) // Interval(2, 3) - * @example * Interval.abs( * Interval(-3, 2) * ) // Interval(0, 3) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -298,18 +324,22 @@ export function abs(x: Interval): Interval { /** * Computes an interval with the maximum values for each endpoint based on `x` * and `y` + * * @example + * ```typescript * Interval.max( * Interval(0, 3), * Interval(1, 2) * ) // Interval(1, 3) + * ``` + * * @param {Interval} x * @param {Interval} y * @return {Interval} */ export function max(x: Interval, y: Interval): Interval { - var badX = utils.isEmpty(x) - var badY = utils.isEmpty(y) + const badX = utils.isEmpty(x) + const badY = utils.isEmpty(y) if (badX && badY) { return constants.EMPTY } else if (badX) { @@ -322,13 +352,16 @@ export function max(x: Interval, y: Interval): Interval { } /** - * Computes an interval with the minimum values for each endpoint based on `x` - * and `y` + * Computes an interval with the minimum values for each endpoint based on `x` and `y` + * * @example + * ```typescript * Interval.min( * Interval(0, 3), * Interval(1, 2) * ) // Interval(0, 2) + * ``` + * * @param {Interval} x * @param {Interval} y * @return {Interval} @@ -349,14 +382,17 @@ export function min(x: Interval, y: Interval): Interval { /** * Creates an interval equal to `x`, equivalent to `Interval().set(x.lo, x.hi)` + * * @example + * ```typescript * Interval.clone( * Interval(1, 2) * ) // Interval(1, 2) - * @example * Interval.clone( * Interval.EMPTY * ) // Interval.EMPTY + * ``` + * * @param {Interval} x * @return {Interval} */ diff --git a/src/operations/relational.ts b/src/operations/relational.ts index 46703d7..699891c 100644 --- a/src/operations/relational.ts +++ b/src/operations/relational.ts @@ -11,16 +11,23 @@ import { Interval } from '../interval' * Checks if the intervals `x`, `y` are equal, they're equal when * `x.lo === y.lo` and `x.hi === y.hi`, a corner case handled is when `x` and * `y` are both empty intervals + * * @example + * ```typescript * Interval.equal( * Interval(2, 3), * Interval(2, 3) * ) // true + * ``` + * * @example + * ```typescript * Interval.equal( * Interval.EMPTY, * Interval.EMPTY * ) // true + * ``` + * * @param {Interval} x * @param {Interval} y * @returns {boolean} @@ -72,21 +79,31 @@ export function assertIncludes(x: number[] | Interval, y: number[] | Interval): /** * Checks if the intervals `x`, `y` are not equal i.e. when the intervals don't * share any value + * * @example + * ```typescript * Interval.notEqual( * Interval(2, 3), * Interval(4, 5) * ) // true + * ``` + * * @example + * ```typescript * Interval.notEqual( * Interval(2, 3), * Interval(3, 5) * ) // false + * ``` + * * @example + * ```typescript * Interval.notEqual( * Interval(2, 4), * Interval(3, 5) * ) // false + * ``` + * * @param {Interval} x * @param {Interval} y * @returns {boolean} @@ -101,16 +118,23 @@ export function notEqual(x: Interval, y: Interval): boolean { /** * Checks if the interval `x` is less than `y` i.e. if all the values of `x` * are lower than the left endpoint of `y` + * * @example + * ```typescript * Interval.lessThan( * Interval(2, 3), * Interval(4, 5) * ) // true + * ``` + * * @example + * ```typescript * Interval.lessThan( * Interval(4, 5), * Interval(2, 3) * ) // false + * ``` + * * @param {Interval} x * @param {Interval} y * @return {boolean} @@ -131,16 +155,23 @@ export const lt = lessThan /** * Checks if the interval `x` is greater than `y` i.e. if all the values of `x` * are greater than the right endpoint of `y` + * * @example + * ```typescript * Interval.greaterThan( * Interval(2, 3), * Interval(4, 5) * ) // false + * ``` + * * @example + * ```typescript * Interval.greaterThan( * Interval(4, 5), * Interval(2, 3) * ) // true + * ``` + * * @param {Interval} x * @param {Interval} y * @return {boolean} @@ -161,11 +192,15 @@ export const gt = greaterThan /** * Checks if the interval `x` is less or equal than `y` i.e. * if all the values of `x` are lower or equal to the left endpoint of `y` + * * @example + * ```typescript * Interval.lessEqualThan( * Interval(2, 3), * Interval(3, 5) * ) // true + * ``` + * * @param {Interval} x * @param {Interval} y * @return {boolean} diff --git a/src/operations/trigonometric.ts b/src/operations/trigonometric.ts index 91edef6..5412b65 100644 --- a/src/operations/trigonometric.ts +++ b/src/operations/trigonometric.ts @@ -43,30 +43,46 @@ function handleNegative(interval: Interval): Interval { /** * Computes the cosine of `x` + * * @example + * ```typescript * Interval.cos( * Interval(0, 0) * ) // Interval(1, 1) + * ``` + * * @example + * ```typescript * Interval.cos( * Interval(0, Math.PI / 2) * ) // Interval(0, 1) + * ``` + * * @example + * ```typescript * Interval.cos( * Interval(3 * Math.PI / 2, 3 * Math.PI) * ) // Interval(-1, 1) + * ``` + * * @example + * ```typescript * Interval.cos( * Interval(-Infinity, x) * ) * // Interval(-1, 1) if x > -Infinity * // Interval.EMPTY otherwise + * ``` + * * @example + * ```typescript * Interval.cos( * Interval(x, Infinity) * ) * // Interval(-1, 1) if x < Infinity * // Interval.EMPTY otherwise + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -113,26 +129,42 @@ export function cos(x: Interval): Interval { /** * Computes the sine of `x` + * * @example + * ```typescript * Interval.sin( * Interval(0, 0) * ) // Interval(0, 0) + * ``` + * * @example + * ```typescript * Interval.sin( * Interval(0, Math.PI / 2) * ) // Interval(0, 1) + * ``` + * * @example + * ```typescript * Interval.sin( * Interval(Math.PI / 2, Math.PI / 2) * ) // Interval(1, 1) + * ``` + * * @example + * ```typescript * Interval.sin( * Interval(Math.PI / 2, -Math.PI / 2) * ) // Interval(-1, 1) + * ``` + * * @example + * ```typescript * Interval.sin( * Interval(Math.PI, 3 * Math.PI / 2) * ) // Interval(-1, 0) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -145,20 +177,30 @@ export function sin(x: Interval): Interval { /** * Computes the tangent of `x` + * * @example + * ```typescript * Interval.tan( * Interval(-Math.PI / 4, Math.PI / 4) * ) // Interval(-1, 1) + * ``` + * * @example + * ```typescript * Interval.tan( * Interval(0, Math.PI / 2) * ) // Interval.WHOLE + * ``` + * * @example + * ```typescript * Interval.tan( * Interval(-Infinity, x) * ) * // Interval.WHOLE if x > -Infinity * // Interval.EMPTY otherwise + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -184,10 +226,14 @@ export function tan(x: Interval): Interval { /** * Computes the arcsine of `x` + * * @example + * ```typescript * Interval.asin( * Interval(-1.57079633, 1.57079633) * ) // Interval(-10, 10) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -202,10 +248,14 @@ export function asin(x: Interval): Interval { /** * Computes the arccosine of `x` + * * @example + * ```typescript * Interval.acos( * Interval(0, 1) * ) // Interval(0, Math.PI / 2) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -220,10 +270,14 @@ export function acos(x: Interval): Interval { /** * Computes the arctangent of `x` + * * @example + * ```typescript * Interval.atan( * Interval(-1, 1) * ) // Interval(-0.785398163, 0.785398163) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -236,10 +290,14 @@ export function atan(x: Interval): Interval { /** * Computes the hyperbolic sine of `x` + * * @example + * ```typescript * Interval.sinh( * Interval(-2, 2) * ) // Interval(-3.6286040785, 3.6286040785) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -252,10 +310,14 @@ export function sinh(x: Interval): Interval { /** * Computes the hyperbolic cosine of `x` + * * @example + * ```typescript * Interval.cosh( * Interval(-2, 2) * ) // Interval(1, 3.76219569108) + * ``` + * * @param {Interval} x * @return {Interval} */ @@ -274,10 +336,14 @@ export function cosh(x: Interval): Interval { /** * Computes the hyperbolic tangent of `x` + * * @example + * ```typescript * Interval.tanh( * Interval(-Infinity, Infinity) * ) // Interval(-1, 1) + * ``` + * * @param {Interval} x * @return {Interval} */ diff --git a/src/operations/utils.ts b/src/operations/utils.ts index efd0ce9..ef3a3b9 100644 --- a/src/operations/utils.ts +++ b/src/operations/utils.ts @@ -7,18 +7,20 @@ import { Interval } from '../interval' /** * Checks if `x` is an interval, `x` is an interval if it's an object which has * `x.lo` and `x.hi` defined and both are numbers + * * @example + * ```typescript * Interval.isInterval( * Interval() * ) // true - * @example * Interval.isInterval( * undefined * ) // false - * @example * Interval.isInterval( * {lo: 1, hi: 2} * ) // true + * ``` + * * @param {*} x * @return {boolean} true if `x` is an interval */ @@ -28,19 +30,21 @@ export function isInterval(x: any): boolean { /** * Checks if `x` is empty, it's empty when `x.lo > x.hi` + * * @example + * ```typescript * Interval.isEmpty( * Interval.EMPTY * ) // true - * @example * Interval.isEmpty( * Interval.WHOLE * ) // false - * @example * Interval.isEmpty( * // bypass empty interval check * Interval().set(1, -1) * ) // true + * ``` + * * @param {Interval} i * @returns {boolean} */ @@ -51,10 +55,14 @@ export function isEmpty(i: Interval): boolean { /** * Checks if an interval is a whole interval, that is an interval which covers * all the real numbers i.e. when `x.lo === -Infinity` and `x.hi === Infinity` + * * @example + * ```typescript * Interval.isWhole( * Interval.WHOLE * ) // true + * ``` + * * @param {Interval} i * @returns {boolean} */ @@ -65,14 +73,17 @@ export function isWhole(i: Interval): boolean { /** * Checks if the intervals `x` is a singleton (an interval representing a single * value) i.e. when `x.lo === x.hi` + * * @example + * ```typescript * Interval.isSingleton( * Interval(2, 2) * ) // true - * @example * Interval.isSingleton( * Interval(2) * ) // true + * ``` + * * @param {Interval} i * @returns {boolean} */ @@ -82,10 +93,14 @@ export function isSingleton(i: Interval): boolean { /** * Checks if zero is included in the interval `x` + * * @example + * ```typescript * Interval.zeroIn( * Interval(-1, 1) * ) // true + * ``` + * * @param {Interval} i * @returns {boolean} */ @@ -95,16 +110,19 @@ export function zeroIn(i: Interval): boolean { /** * Checks if `value` is included in the interval `x` + * * @example + * ```typescript * Interval.hasValue( * Interval(-1, 1), * 0 * ) // true - * @example * Interval.hasValue( * Interval(-1, 1), * 10 * ) // false + * ``` + * * @param {Interval} i * @param {number} value * @returns {boolean} @@ -118,16 +136,19 @@ export function hasValue(i: Interval, value: number): boolean { /** * Checks if `x` is a subset of `y` + * * @example + * ```typescript * Interval.hasInteravl( * Interval(0, 3), * Interval(1, 2) * ) // true - * @example * Interval.hasInteravl( * Interval(0, 3), * Interval(1, 4) * ) // false + * ``` + * * @param {Interval} x * @param {Interval} y * @returns {boolean} @@ -140,28 +161,28 @@ export function hasInterval(x: Interval, y: Interval): boolean { } /** - * Checks if the intervals `x`, `y` overlap i.e. if they share at least one - * value + * Checks if the intervals `x`, `y` overlap i.e. if they share at least one value + * * @example + * ```typescript * Interval.intervalsOverlap( * Interval(0, 3), * Interval(1, 2) * ) // true - * @example * Interval.intervalsOverlap( * Interval(0, 2), * Interval(1, 3) * ) // true - * @example * Interval.intervalsOverlap( * Interval(0, 2), * Interval(2, 3) * ) // true - * @example * Interval.intervalsOverlap( * Interval(0, 1), * Interval(2, 3) * ) // false + * ``` + * * @param {Interval} x * @param {Interval} y * @returns {boolean}