### MiniM. Saving time.

MiniM Overview
MiniM Knowledge Base | Jun 11, 2010

On the canonical numerical indices representation in the MUMPS language

An important issue in the language MUMPS is an understanding of the canonical numerical indices representation. MUMPS is the language defined that language is typeless and its strings and numbers are treated alike, differ only in the context of operations. On the other hand, in the language defined the index sorting rule - first is the empty string, then the numbers in an arithmetical order, then the strings in string sorting order.

In order to determine whether to use the string as a number, in the MUMPS language is defined rules for canonical numeric representation.

1. The string is not a canonical number, if it has leading zeros.

2. The string is not a canonical number, if there is zero terminator is not included to the exponential part.

3. The string is not a canonical number, if there is a decimal point, after which no figures.

4. The string is not a canonical number, if it contains a leading "+" sign or more then one "-" signs.

Here are examples:

```USER>s a("1.0")="1.0"

USER>s a("01.")="01.0"

USER>s a("01.0")="01.0"

USER>s a("1.")="1."

USER>s a("1")="1"

USER>s a("01")="01"

USER>s a("-1")="-1"

USER>s a("+1")="+1"

USER>w
a(-1)="-1"
a(1)="1"
a("+1")="+1"
a("01")="01"
a("01.")="01.0"
a("01.0")="01.0"
a("1.")="1."
a("1.0")="1.0"
```

Here are only two canonical numers representation cases:

```a(-1)="-1"
a(1)="1"
```

Other cases are not under one or more canonical numbers definition rules.

5. A separate case is the exponential form of numbers. In this case, the system tries to determine the canonicity of way to bring it to the number, followed by reduction to string the base 10 and compare the result with the original string. If the values match, the string is the canonical number.

Here are examples:

```USER>s a("1e100")="1e100"

USER>s a("1E+100")="1E+100"

USER>w
a(1E+100)="1E+100"
a("1e100")="1e100"
```

Here we use two different forms of the same number, but only one of them match to the canonical representation, and the system is treated as a number.

These examples are made using the MiniM Database Server. The developer must understand when developing or porting programs that set of rules 1 - 4 is standard and mandatory, and 5 - can be vendor-specific. In other implementations MUMPS system behavior can vary.

In any case, if you want guaranteed interpreted a string in the index as a number, it should be applied to math operation +. In this case the system lead the string in its internal format to the number and use the string as a numeric index. In our example:

```USER>s a(+"1e100")="1e100"

USER>s a(+"1E+100")="1E+100"

USER>w
a(1E+100)="1E+100"
```

Here, both entries were made in the same name and it's left to do the last assignment.

Eugene Karataev
support@minimdb.com