Skip to main content
Question

String Comparison

  • July 6, 2026
  • 2 replies
  • 59 views

ANTHONY PONTECORVO

Universe 11.3.1,  AIX 7200-05-11-2546

We noticed when comparing very large numbers they don’t correctly evaluate to not equal. Specifically, if two variables are over 17 characters in length and they don’t match correctly. See the below sample program and its output. The (X NE Y) does not evaluate to true until the length of the strings are 17 characters even though the variables are never equal. Does anyone know what is causing this to happen? 

 

X = '0587634906513946593645'

Y = '0587634906513946593646'

 

FOR Z = 1 TO 8

  CRT X, Y, (X NE Y),LEN(X)

  STRLN = LEN(X)

  X = RIGHT(X,STRLN-1)

  Y = RIGHT(Y,STRLN-1)

NEXT Z

Output:

0587634906513946593645        0587634906513946593646        0         22        
587634906513946593645         587634906513946593646         0         21        
87634906513946593645          87634906513946593646          0         20        
7634906513946593645 7634906513946593646 0         19                            
634906513946593645  634906513946593646  0         18                            
34906513946593645   34906513946593646   1         17                            
4906513946593645    4906513946593646    1         16                            
906513946593645     906513946593646     1         15                            
>                                                                               

 

2 replies

Brian Speirs
Forum|alt.badge.img
  • Participating Frequently
  • July 6, 2026

You are hitting the limits of numeric precision. The documentation does note this, but it is well hidden.

Try this program instead.

PROGRAM NTEST

X = '0587634906513946593645'
Y = '0587634906513946593646'

FOR Z = 1 TO 8
CRT X 'L#25' : Y 'L#25' : ' ' : SCMP(X, Y) : ' ' : LEN(X)
STRLN = LEN(X)
X = RIGHT(X,STRLN-1)
Y = RIGHT(Y,STRLN-1)
NEXT Z

END

Output (in OpenQM):

0587634906513946593645   0587634906513946593646     -1  22
587634906513946593645    587634906513946593646      -1  21
87634906513946593645     87634906513946593646       -1  20
7634906513946593645      7634906513946593646        -1  19
634906513946593645       634906513946593646         -1  18
34906513946593645        34906513946593646          -1  17
4906513946593645         4906513946593646           -1  16
906513946593645          906513946593646            -1  15

Cheers,

 

Brian

 


Jeff Kendrick
  • New Participant
  • July 7, 2026

I’ve dealt with this by appending an alpha character to each side of the comparison. That forces a string comparison which will work as expected. However, it won’t help if you need to do any kind of math with numbers that big, it’s only good for comparisons.