The &NUMBER String Function The &NUMBER String Function

Perhaps one of the most useful string functions is the function:

     &NUMBER(TYPE, NUM(1), NUM(2), .......)

This function has an option keyword, TYPE, and a set of strings which are normally numbers. Here, the valid forms of the function are:

     &NUMBER(SIN,  RN)
     &NUMBER(COS,  RN)
     &NUMBER(TAN,  RN)
     &NUMBER(ATAN2, X, Y )
     &NUMBER(LN,  RN)
     &NUMBER(EXP,  RN)
     &NUMBER(ABS,  RN)
     &NUMBER(MIN,  RN(1), RN(2), ...)
     &NUMBER(MAX,   RN(1), RN(2), ...)
     &NUMBER(MEAN,   RN(1), RN(2), ...)
     &NUMBER(SORT,  RN(1), RN(2), ...)
     &NUMBER(INTERPOLATE,   X, X(1), ... Y(n))
     &NUMBER(NORM,   RN(1), RN(2), ...)
     &NUMBER(DOT,   RN(1), RN(2), ...)
     &NUMBER(UNIT_VEC,   RN(1), RN(2), ...)
     &NUMBER(CROSS,   RN(1), RN(2), ...)
     &NUMBER(SCALE,  SF, RN(1), ...)
     &NUMBER(ADDV,   SF, RN(1), ...)
     &NUMBER(3PTS2Q, P1(1), P1(2),  ... P3(3))
     &NUMBER(VECG2L, Q VG(1), VG(2), VG(3) )
     &NUMBER(VECL2G, Q VL(1), VL(2), VL(3) )

The result produced depends, of course, upon the value of TYPE. The first option, ?, is different from the others, in that it returns a value of .TRUE. if the string is a valid number or .FALSE. if it is not. All of the others return a set of numbers.

As an example of how these functions operate, consider the following:

     &NUMBER(REAL, (2+3)**8/2.)

This function will read the string "(2+3)**8/2." and convert it to a number, and then convert this number back into a string with eight significant figures. It is this final string which will be passed to the command interpreter. The function with a type of INTEGER operates in a similar manner, except that here, the result will be an integer. The idea behind these two is that in some cases a string representing a number may become too long to convert; therefore, strings can be "compressed" with this function.

The first several TYPEs take a single number as input and return a single number. The particular conversion which occurs with most values of TYPE is rather obvious from the name. In particular, SIN, COS, TAN produce strings with the value of the trigonometric functions of the same name and with the argument in radians. The trigonometric functions which end in D assume that the argument will be in degrees. The functions ATAN, ATAN2, ACOS, and ASIN are inverse trigonometric functions, and ATAN2 returns the angle who's tan is X/Y. The angles returned here are in radians. The types of LN, EXP, SQRT, and ABS produce the natural logarithm, the exponential, the square root, and the absolute value respectively.

The remainder of TYPEs take more than a single number as arguments. The MAX and MIN return the extremes of the arguments. A type of MEAN returns the mean of a set of numbers, while a a type of SORT sorts a set of numbers in ascending order. INTERPOLATE takes the first number as the desired "X" value, the next N/2 numbers as an array of Xs and the last N/2 numbers as an array of Ys. It returns the Y values which corresponds to the first number input. Of course, the X values must be in increasing order.

The next remainder of TYPEs allow one to treat strings as vectors of numbers. For a type of NORM, MOSES will return a string which is the square root of the sum of the squares of the numerical arguments. For a TYPE of DOT, the number of numerical arguments must be divisible by two, and it returns the inner product of two vectors represented by the 2*n numbers. With UNIT_VEC the value returned is the input vector scaled by its length. With SCALE, the first number is a multiplier and the function will return N numbers which represent the remaining numbers multiplied by the first. ADDV takes the first number and uses it as a scalar multiplier for the first N/2 numbers and it vectorially adds the result to the second N/2 numbers.

The last three functions deal with matrices and vectors. The TYPE 3PTS2Q returns a direction cosine matrix. Here P1, P2, and P3 are the coordinates of three points (You need nine numbers here). The "origin" of the local system is at P1. The vector from P1 to P2 points "in the direction of the local X axis, and the vector from P1 to P3 points in the direction of the local Z axis. This direction cosine matrix will transform local vectors into global ones. The TYPE VECG2L transforms a vector in global coordinates to local ones and VECL2G performs the inverse. Here Q is a direction cosine matrix (there are nine numbers for Q) VG is a vector in global coordinates and VL is a vector in local coordinates.