GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


abs(n) without conditional branching by DELTRON
// ** The absolute value of n without introducing conditional branching - DELTRON 9/22/04

#include <iostream>
using namespace std;

void main(void)
{
    int n=-10;

    for (int i=0; i<15; i++)
    {
        int result = ((1*(~n+1))*(n<0))+((n>0)*n);
        printf("n = %i, abs(n) = %i\n",n,result);
        n++;
    }