CONTENTS | INDEX | PREV | NEXT

 abs
 labs 

 NAME
  abs - take absolute value of int
  labs- take absolute value of long

 SYNOPSIS
  #include <stdio.h>
  #include <stdlib.h>

  int r = [l]abs(n);
  int n;

  UNDER DICE, sizeof(int) == sizeof(long) and these two functions are
  thus identical.

 FUNCTION
  Returns the absolute value of the specified integer.  I.E. r == n
  if n >= 0, r = -n (positive) if n < 0.  Note that normally one would
  not use this call due to overhead, but it exists for compatibility.

  Warning:    the absolute value of 0x80000000 cannot be taken.
          0x80000000 will be returned.

 EXAMPLE
  #include <stdio.h>
  #include <stdlib.h>

  main()
  {
      int n = -53;

      printf("The absolute value of %d is %dn", n, abs(n));
      sleep(1);
      printf("But its faster if you write a macro:n");

  #define abs(x)  (((x) < 0) ? -(x) : (x))

      sleep(1);
      printf("The absolute value of %d is %dn", n, abs(n));
      return(0);
  }


 INPUTS
  int n;      integer

 RESULTS
  int r;      absolute value of integer