Next Previous Up Contents
Next: Arrays
Up: Functions
Previous: Functions

#### 10.7.1 Arithmetic

Standard arithmetic functions including things like rounding, sign manipulation, and maximum/minimum functions. Phase folding operations, and a convenient form of the modulus operation on which they are based, are also provided.

`roundUp( x )`
  Rounds a value up to an integer value. Formally, returns the smallest (closest to negative infinity) integer value that is not less than the argument.

  - Parameters:
    - `x` (floating point): a value.
  - Return value
    - (integer): `x` rounded up
`roundDown( x )`
  Rounds a value down to an integer value. Formally, returns the largest (closest to positive infinity) integer value that is not greater than the argument.

  - Parameters:
    - `x` (floating point): a value
  - Return value
    - (integer): `x` rounded down
`round( x )`
  Rounds a value to the nearest integer. Formally, returns the integer that is closest in value to the argument. If two integers are equally close, the result is the even one.

  - Parameters:
    - `x` (floating point): a floating point value.
  - Return value
    - (integer): `x` rounded to the nearest integer
`roundDecimal( x, dp )`
  Rounds a value to a given number of decimal places. The result is a `float` (32-bit floating point value), so this is only suitable for relatively low-precision values. It's intended for truncating the number of apparent significant figures represented by a value which you know has been obtained by combining other values of limited precision. For more control, see the functions in the `Formats` class.

  - Parameters:
    - `x` (floating point): a floating point value
    - `dp` (integer): number of decimal places (digits after the decimal point) to retain
  - Return value
    - (floating point): floating point value close to `x` but with a limited apparent precision
  - Example:
    - `roundDecimal(PI,2) = 3.14f`
`abs( x )`
  Returns the absolute value of an integer value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

  - Parameters:
    - `x` (integer): the argument whose absolute value is to be determined
  - Return value
    - (integer): the absolute value of the argument.
`abs( x )`
  Returns the absolute value of a floating point value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

  - Parameters:
    - `x` (floating point): the argument whose absolute value is to be determined
  - Return value
    - (floating point): the absolute value of the argument.
`max( a, b )`
  Returns the greater of two integer values. If the arguments have the same value, the result is that same value.

  Multiple-argument maximum functions are also provided in the `Arrays` and `Lists` packages.

  - Parameters:
    - `a` (integer): an argument.
    - `b` (integer): another argument.
  - Return value
    - (integer): the larger of `a` and `b`.
`maxNaN( a, b )`
  Returns the greater of two floating point values. If the arguments have the same value, the result is that same value. If either value is blank, then the result is blank.

  - Parameters:
    - `a` (floating point): an argument.
    - `b` (floating point): another argument.
  - Return value
    - (floating point): the larger of `a` and `b`.
`maxReal( a, b )`
  Returns the greater of two floating point values, ignoring blanks. If the arguments have the same value, the result is that same value. If one argument is blank, the result is the other one. If both arguments are blank, the result is blank.

  Multiple-argument maximum functions are also provided in the `Arrays` and `Lists` packages.

  - Parameters:
    - `a` (floating point): an argument
    - `b` (floating point): another argument
  - Return value
    - (floating point): the larger non-blank value of `a` and `b`
`min( a, b )`
  Returns the smaller of two integer values. If the arguments have the same value, the result is that same value.

  Multiple-argument minimum functions are also provided in the `Arrays` and `Lists` packages.

  - Parameters:
    - `a` (integer): an argument.
    - `b` (integer): another argument.
  - Return value
    - (integer): the smaller of `a` and `b`.
`minNaN( a, b )`
  Returns the smaller of two floating point values. If the arguments have the same value, the result is that same value. If either value is blank, then the result is blank.

  - Parameters:
    - `a` (floating point): an argument.
    - `b` (floating point): another argument.
  - Return value
    - (floating point): the smaller of `a` and `b`.
`minReal( a, b )`
  Returns the smaller of two floating point values, ignoring blanks. If the arguments have the same value, the result is that same value. If one argument is blank, the result is the other one. If both arguments are blank, the result is blank.

  Multiple-argument minimum functions are also provided in the `Arrays` and `Lists` packages.

  - Parameters:
    - `a` (floating point): an argument
    - `b` (floating point): another argument
  - Return value
    - (floating point): the larger non-blank value of `a` and `b`
`mod( a, b )`
  Returns the non-negative remainder of `a/b`. This is a modulo operation, but differs from the expression `a%b` in that the answer is always >=0 (as long as `b` is not zero).

  - Parameters:
    - `a` (floating point): dividend
    - `b` (floating point): divisor
  - Return value
    - (floating point): non-negative remainder when dividing `a` by `b`
  - Examples:
    - `modulo(14, 5) = 4`
    - `modulo(-14, 5) = 1`
    - `modulo(2.75, 0.5) = 0.25`
`phase( t, period )`
  Returns the phase of a value within a period.

  For positive period, the returned value is in the range [0,1).

  - Parameters:
    - `t` (floating point): value
    - `period` (floating point): folding period
  - Return value
    - (floating point): mod(t,period)/period
  - Examples:
    - `phase(7, 4) = 0.75`
    - `phase(-1000.5, 2.5) = 0.8`
    - `phase(-3300, 33) = 0`
`phase( t, period, t0 )`
  Returns the phase of an offset value within a period. The reference value `t0` corresponds to phase zero.

  For positive period, the returned value is in the range [0,1).

  - Parameters:
    - `t` (floating point): value
    - `period` (floating point): folding period
    - `t0` (floating point): reference value, corresponding to phase zero
  - Return value
    - (floating point): phase(t-t0, period)
  - Examples:
    - `phase(5003,100,0) = 0.03`
    - `phase(5003,100,2) = 0.01`
    - `phase(5003,100,4) = 0.99`
`phase( t, period, t0, phase0 )`
  Returns the offset phase of an offset value within a period. The reference value `t0` corresponds to integer phase value, and the phase offset `phase0` determines the starting value for the phase range.

  For positive period, the returned value is in the range [`phase0`,`phase0+1`).

  - Parameters:
    - `t` (floating point): value
    - `period` (floating point): folding period
    - `t0` (floating point): reference value, corresponding to phase zero
    - `phase0` (floating point): offset for phase
  - Return value
    - (floating point): offset phase
  - Examples:
    - `phase(23,10,1,99) = 99.2`
    - `phase(8.6125,0.2,0.0125,-0.3) = 0`
    - `phase(8.6125,0.2,0.1125,-0.7) = -0.5`

Next Previous Up Contents
Next: Arrays
Up: Functions
Previous: Functions

STILTS - Starlink Tables Infrastructure Library Tool Set
Starlink User Note256
STILTS web page: http://www.starlink.ac.uk/stilts/
Author email: m.b.taylor@bristol.ac.uk
Mailing list: topcat-user@jiscmail.ac.uk