// This is a component for LinuxCNC HAL // Copyright 2011 Sebastian Kuzminsky // // This program is free software; you can redistribute it and/or // modify it under the terms of version 2 of the GNU General // Public License as published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. component abs_s32 "Compute the absolute value and sign of the input signal"; pin in s32 in "input value" ; pin out s32 out "output value, always non-negative"; pin out bit sign "Sign of input, false for positive, true for negative" ; pin out bit is_positive "TRUE if input is positive, FALSE if input is 0 or negative"; pin out bit is_negative "TRUE if input is negative, FALSE if input is 0 or positive"; function _ nofp; license "GPL"; author "Sebastian Kuzminsky"; ;; FUNCTION(_) { rtapi_s32 tmp = in; if ( tmp >= 0 ) { sign = 0; out = tmp; } else { sign = 1; out = -tmp; } if (tmp > 0) is_positive = 1; else is_positive = 0; if (tmp < 0) is_negative = 1; else is_negative = 0; }