Skip to main content
Question

String Comparison

  • July 6, 2026
  • 4 replies
  • 117 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                            
>                                                                               

 

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


Forum|alt.badge.img
  • Rocketeer
  • July 8, 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. 

If you do not want string operations that is very custom requirement. Basic is Scripting Layer and not math framework with huge number support and it will not help directly.
Universe casts depending on args to 64 bit integer or double and does math operations, which reasonable limitation. Numbers over 17 chars substantially overflow 64bits.

If you have large numbers and need math, use u2PY and pythons big number support or awesome libraries like numpy. https://docs.rocketsoftware.com/bundle/universepython_ug_1221/page/khv1686929749199.html

If you for some reason cannot or want python, you have GCI https://docs.rocketsoftware.com/bundle/universegciuser_ug_1141/page/dpg1721820349090.html

Define your own C functions, receive basic string args, and pass to any math frameworks.


Gregor Scott
Forum|alt.badge.img+4
  • Participating Frequently
  • July 17, 2026

Try using the `COMPARE()` function in BASIC.

It will compare the values as strings instead of numbers and return either -1, 0 or 1 depending on the comparison result.

In your example code you could simply use `NOT(COMPARE(X,Y,”R”))` in place of the `(X NE Y)` logic