How to find the ABS of std_logic_vector

Discussion in 'VHDL' started by priya, Nov 21, 2006.

  1. priya

    priya Guest

    hi
    ABS function which is specified for integer type in VHDL
    for slv data type
    how to find the absolute value
    reply back soon
     
    priya, Nov 21, 2006
    #1
    1. Advertising

  2. priya

    Ajeetha Guest

    Re: How to find the ABS of std_logic_vector

    How about:

    abs(to_integer(unsigned(my_slv)));


    Use ieee.numeric_std package

    Try it out and let me know if it works

    Ajeetha, CVC
    www.noveldv.com

    priya wrote:
    > hi
    > ABS function which is specified for integer type in VHDL
    > for slv data type
    > how to find the absolute value
    > reply back soon
     
    Ajeetha, Nov 21, 2006
    #2
    1. Advertising

  3. priya schrieb:

    > ABS function which is specified for integer type in VHDL
    > for slv data type
    > how to find the absolute value



    No one knows, if your std_(u)logic_vector is signed or not. Therefore
    there is no such function.

    my_abs<=abs( signed(my_stdlogicvector) ); -- using IEEE.numeric_std

    Ralf
     
    Ralf Hildebrandt, Nov 21, 2006
    #3
  4. priya

    Andy Guest

    Re: How to find the ABS of std_logic_vector

    I'm assuming the OP wants an SLV back, so:

    my_abs <= std_logic_vector(abs(signed(my_slv)));

    Or just use constrained integers or numeric-std.signed/unsigned instead
    of slv for the data in the first place, and no conversions would be
    necessary.

    Andy


    Ralf Hildebrandt wrote:
    > priya schrieb:
    >
    > > ABS function which is specified for integer type in VHDL
    > > for slv data type
    > > how to find the absolute value

    >
    >
    > No one knows, if your std_(u)logic_vector is signed or not. Therefore
    > there is no such function.
    >
    > my_abs<=abs( signed(my_stdlogicvector) ); -- using IEEE.numeric_std
    >
    > Ralf
     
    Andy, Nov 21, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Math.abs

    , Nov 9, 2005, in forum: Java
    Replies:
    37
    Views:
    14,692
    Oliver Wong
    Nov 14, 2005
  2. Daniel Heiserer
    Replies:
    2
    Views:
    772
    Chris Dams
    Sep 23, 2003
  3. Aaron Gallimore

    C++ abs() function

    Aaron Gallimore, Feb 24, 2004, in forum: C++
    Replies:
    5
    Views:
    96,750
    Rob Williscroft
    Feb 24, 2004
  4. Klaas Vantournhout

    f2c's abs conflicts with <complex> abs

    Klaas Vantournhout, Oct 31, 2006, in forum: C++
    Replies:
    3
    Views:
    388
    Victor Bazarov
    Oct 31, 2006
  5. Thomas Rouam
    Replies:
    6
    Views:
    1,134
Loading...

Share This Page