Menu

abs() seems not working correctly

li li
2011-06-25
2012-09-15
  • li li

    li li - 2011-06-25

    Hi Guys,

    I found an very interesting situation. When I use abs() to find absolute value
    of the number, the abs() return the values as function floor() did in MATLAB.
    I am not sure it is designed on purpose or it is a bug. If anyone know it,
    please let me know. I am looking forward to your response. See below the
    examples. The first values is the original value, and the second is the abs
    value.

    llr:0.460886

    abs_llr:0

    llr:0.499698

    abs_llr:0

    llr:0.808538

    abs_llr:0

    llr:-0.503686

    abs_llr:0

    llr:-3.66944

    abs_llr:3

    llr:0.139525

    abs_llr:0

    llr:0.53825

    abs_llr:0

    llr:0.154884

    abs_llr:0

    llr:-4.47081

    abs_llr:4

    llr:4.52294

    abs_llr:4

    llr:-0.585991

    abs_llr:0

    llr:0.559954

    abs_llr:0

    llr:4.4835

    abs_llr:4

    llr:0.530505

    abs_llr:0

    llr:0.601909

    abs_llr:0

    llr:-0.74995

    abs_llr:0

     
  • Laurent Schmalen

    abs() is not a feature of IT++ but of the C++ math library. Unfortunately,
    abs() only accepts integers at its input and outputs an integer, in your case,
    an implicit typecast is performed, which is why you see rounded values.

    Try replacing abs(x) by fabs(x) and it should work

     

Log in to post a comment.