-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathabs_s64.comp
More file actions
50 lines (46 loc) · 1.61 KB
/
abs_s64.comp
File metadata and controls
50 lines (46 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// This is a component for Machinekit
// Copyright 2011 Sebastian Kuzminsky <seb@highlab.com>
//
// Adapted for 64 bit ArcEye <arceyeATmgwareDOTcoDOTuk>
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
component abs_s64 "Compute the absolute value and sign of the input signal";
pin in s64 in "input value" ;
pin out s64 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";
option period no;
function _;
license "GPL";
author "ArcEye based on code from Sebastian Kuzminsky";
;;
FUNCTION(_)
{
if ( in >= 0 ) {
sign = false;
out = in;
} else {
sign = true;
out = -in;
}
if (in > 0)
is_positive = true;
else
is_positive = false;
if (in < 0)
is_negative = true;
else
is_negative = false;
}