Next Previous Up Contents
Next: TrigDegrees
Up: General Functions
Previous: Arrays

### B.1.7 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.
  - `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.
  - `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.
  - `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.
  - `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
`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.
  - `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.
  - `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.

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

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

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

  - `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).
  - `a` (floating point): dividend
  - `b` (floating point): divisor
  - return value (floating point): non-negative remainder when dividing `a` by `b`
`phase( t, period )`
  Returns the phase of a value within a period.

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

  - `t` (floating point): value
  - `period` (floating point): folding period
  - return value (floating point): mod(t,period)/period
`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).

  - `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)
`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`).

  - `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

Next Previous Up Contents
Next: TrigDegrees
Up: General Functions
Previous: Arrays

TOPCAT - Tool for OPerations on Catalogues And Tables
Starlink User Note253
TOPCAT web page: http://www.starlink.ac.uk/topcat/
Author email: m.b.taylor@bristol.ac.uk
Mailing list: topcat-user@jiscmail.ac.uk