Saturday, September 27, 2014

X++ Operators Div and Mod Behave Differently in .NET CIL, in AX 2012

X++ operators div and mod in CIL can cast their operands differently and return result of different base types compared to X++ interpreter. Consider these examples:
Test operationX++ resultsCIL results
0 div 2Integer0Int640
intMax() div 2Integer1073741823Int641073741823
realMax() div 2Integer1073741823Int644999999999999999
int64Max() div 2Int644611686018427387903Int644611686018427387903
intMax() mod 2Integer1Integer1
realMax() mod 2Integer1Real1,00
int64Max() mod 2Int641Int641

Tested in AX 2012 R2 with kernel builds 6.2.1000.4051 (CU7) and 6.2.1000.8310.