Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - abs() return absolute value http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 abs()               Return absolute value
------------------------------------------------------------------------------
 Declaration
   math.hdr

 Syntax
   func dbl abs extern
   param value dbl eNumber

 Arguments
   eNumber is a numeric expression.

 Return
   The absolute value of the passed numeric.

 Description
   The abs() function returns the absolute value of eNumber, i. e. negative
   values are converted into positive values.

 Example
   #define EXAMPLE_MATH
   #include example.hdr

   proc Test_abs
   vardef
     int nVal1, nVal2
   enddef
   
   clear
   
   ? abs(  100 )          // Displays   100
   ? abs( -100 )          // Displays   100
   ? abs(    0 )          // Displays     0
   
   // This demonstrates how abs() can be used to determine the difference
   // between two numbers, no matter in which order they are passed.
   //
   nVal1 := 100
   nVal2 := 150
   
   ? nVal1 - nVal2        // Displays   -50
   ? nVal2 - nVal1        // Displays    50
   ? abs( nVal1 - nVal2 ) // Displays    50
   ? abs( nVal2 - nVal1 ) // Displays    50
   endproc

   proc main
   Test_abs()
   endproc

See Also: trunc()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson