Abs
PositiveResult = Abs(InputValue)
 
Parameters:

    InputValue = Then Value/Variable or expression you wish to return the absolute (positive) value of
Returns:

    PositiveResult = The Abs function always returns a positive result
 

      The Abs function takes the input value or expression and returns this value in a positive form. So negative values will be returned as postives while postives will be unchanged.



FACTS:


      * Abs returns a positive result no matter what the input.

      * The Abs function was changed in from PlayBASIC V1.64M (And above), so that it now returns Integers when you feed Integers and Floats when you feed it floats. Older versions always returned floats.




Mini Tutorial:


      Showing the effect of the ABS function on the values -100 and 100.

  
; display the absolute value of -100
  Print Abs(-100)
  
; display the absolute value of 100
  Print Abs(100)
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  



This example would output.

  
  100
  100
  





Mini Tutorial:


Using ABS to ensure results are always positive.

  
  
; create a for loop from 0 to 10
  For lp=0 To 10
   ; display the absolute value of  0 minus the loop counter.
     Print Abs(0-lp)
  Next lp
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  


This example would output.

  
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
  

 
Related Info: Ceil | Int | Neg | Sgn :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com