Sign function

Hi All,

Sign function doesn't work correctly in AX 2009 and 2012. It should returns -1 for negative numbers, 0 for zero and +1 for positive numbers. But  it gives -1 for negative and +1 for others.

Sign at Global:


static real sign(real num)
    return num >= 0 ? 1 : -1;


My correction:

static int sign(real num)

   if (num < 0)

    return -1;

    return num >= 0 ? 1 : 0;

  • Hi Metin,

    Do you have any idea where this method is used in the standard and what regressions can be caused changing this code?
    Also I'm sorry to say, but the outcome of your code is still the same as the standard code...
    If you really want to have a zero, probably estimate the impact first. Maybe it would be better to create a new "MetinSign" function, but then also don't use "num >= 0" but "num > 0".
Reply Children
No Data