If +value=value

This classic code is good for checking if the value is *canonical* number, while the term *number* can be interpreted in some other ways, e.g. a number in scientific format, double precision number, etc. Caché has a set of out-of-the-box functions to perform some of these checks, e.g. $isvalidnum, $isvaliddouble, $number, $normalize.

So, the answer depends on topic starter's conditions.

E.g., if I need to check if a number is a __numlit__ (scientific numbers and numbers with starting zeroes are allowed), I'd use `$isvalidnum(x)`. Addition check on being integer (an __intlit__) can look like: `$isvalidnum(x)&&(+x\1=+x)`. Here are some testing results:

USER> w !,?6,"Is number?",?20,"Is integer?",?35,"Is canonic?"
USER> for x="001a","002",0,1,"-1.2","+1.3","1E3" w !,x,?10," ",$isvalidnum(x),?20," ",$isvalidnum(x)&&(+x\1=+x),?35,x=+x
Is number? Is integer? Is canonic?
001a 0 0 0
002 1 1 0
0 1 1 1
1 1 1 1
-1.2 1 0 1
+1.3 1 0 0
1E3 1 1 0

In other conditions I'd write another code. There is no universal answer to topic starter's question.

P.S. As to "Annotated MUMPS Standard" (http://71.174.62.16/Demo/AnnoStd):

An __intlit__ is not necessarily a canonic representation of a number.

A __numlit__ is not necessarily a canonic representation of a number.

The reduction to a canonical numeric representation involves (colloquially) the removal of any redundant leading and trailing zeroes, the conversion of exponentionential notation to "mantissa only" notation, and the reduction of any leading plus (`+`) and minus (`-`) signs to at most one leading minus sign (see also Numeric interpretation of data).

Are you sure that this will work?

USER > set number = "21d20"USER > if (number\1 = +number) { w "number and integer" } else { w "not number and not integer" }will output that it is "number and integer", because

number\1will turn string "21d20" to "21" as a result.Moreover

+numberwill result from "21d20" to "21" ... and will tell that really 21 equals 21 ... but "21d20" is not numberYou are right. The check for pure number got lost

if +number=numberhas to precedeso the combined is

if +number=number,number\1=+numberI believe that would be equal to just

`if number\1=number`

This is a matter of interpretation.

If you also allow leading 0 for integers (eg. 00123) then you need to normalize it.

But

if +number=number,number\1=+numberdoesn't allow leading zeroes either.

right.