Hi Guys,
An Abs() function will always return a positive value, thus stripping the -ve sign if its present.
Is there a cute way of doing this in FC?
can it be done in a C component?
FCV_Var1 = abs(FCV_Var2);
How can I do an Absolute Function Abs
Moderator: Benj
Re: How can I do an Absolute Function Abs
Ok..
Yep a line of C seem to do the trick.
Since C does not simulate, tested OK on hardware. MIAC dsPIC, which is the test brick of choice this week!! if anyone knows a reason this may not be the best route ( or if its native to FC), let me know.
J.
Yep a line of C seem to do the trick.
Since C does not simulate, tested OK on hardware. MIAC dsPIC, which is the test brick of choice this week!! if anyone knows a reason this may not be the best route ( or if its native to FC), let me know.
-
kersing
- Valued Contributor

- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: How can I do an Absolute Function Abs
How about creating a macro that checks if the input < 0, if so return -input else return input
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
Re: How can I do an Absolute Function Abs
HI Jay,
Other than specific info from Ben the way I could you not consider the number type and where and how the sign is stored eg the last bit is set (asm). Store the value carry out the ABS command and reintroduce possibly. alternatively if you know would the sign should be after calculation multiple the answer by -1
Matt
Other than specific info from Ben the way I could you not consider the number type and where and how the sign is stored eg the last bit is set (asm). Store the value carry out the ABS command and reintroduce possibly. alternatively if you know would the sign should be after calculation multiple the answer by -1
Matt
Last edited by Docara on Sat Jul 01, 2017 2:02 am, edited 1 time in total.
Re: How can I do an Absolute Function Abs
Thanks Kersing & Matt;
Yes, I was doing a check for <0 and then inverting previously, it just seemed a bit clunky.. but then again in FC, so is un-simulateable C
For me at least checking for the signed bit, is a bit more work than I really wanted but its a darn good alternative to consider for other applications.
Thanks guys. J.
EDIT
On reflection and having cleaned up other garbage in my development FC, your method is neater! Thanks.
Yes, I was doing a check for <0 and then inverting previously, it just seemed a bit clunky.. but then again in FC, so is un-simulateable C
For me at least checking for the signed bit, is a bit more work than I really wanted but its a darn good alternative to consider for other applications.
Thanks guys. J.
EDIT
On reflection and having cleaned up other garbage in my development FC, your method is neater! Thanks.