Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actuallomateron

Posted 13 June 2013 - 08:30 PM

I have this code

 

float Code(float a,float b, int c)

{

    float r=0;

 

      if( c==0)

      {

           r=a*b;

      }

     else if( c==1)

     {

           r=a/b;

     }

     else if( c==2)

     {

          r=2*a;

     }

 

     return r;

}

 

 

 

Lets say i don't have 3 different "if" but a thousand different "if", and "c" as it is in the code just selects one "if" 

 

Has anyone think about a way to make this faster by creating a way of recompiling the code so it deletes all the unnecessary "if" lines in the assembly code

 

Or is there anything related to this that solves the problem in a different way?


#1lomateron

Posted 13 June 2013 - 05:39 PM

I have this code

 

float Code(float a,float b, int c)

{

    float r=0;

 

      if( c==0)

      {

           r=a*b;

      }

     else if( c==1)

     {

           r=a/b;

     }

     else if( c==2)

     {

          r=2*a;

     }

 

     return r;

}

 

 

 

Lets say i don't have 3 different "if" but a thousand different "if", and "c" as it is in the code just selects one "if" 

 

the variable "c" is defined when the application is running, and can be changed

 

Has anyone think about a way to make this faster by creating a way of recompiling the code so it deletes all the unnecessary "if" lines in the assembly code

 

Or is there anything related to this that solves the problem in a different way?

 

 


PARTNERS