Re: absolute function
- Posted by Vinoba Mar 28, 2011
- 3358 views
return s * sign ( s )
This code and similar other single line codes I have tried are easy to understand and bullet proof and valid for atoms or sequences, but as Matt quite rightly says, the current lengthy code with branching and iteration is still the fastest! One can blame the multiply and other functions people have used, but this can only get us into more lengthy debates. I have accepted the current code as the fastest, but am using one line code in place without calling the actual abs() function.
include std\math.e sequence vec = { 23.456, -76.893, -34.5, 0, 23.55 } ? vec ? vec * sign (vec) -- you could use this ? abs (vec) -- instead of this inside of a long series of math operations -- althouth the latter is faster -- if you are worried about the multi-line abs function or the iteration therein.
But then, even then sign function is also not straightforward