 # Using a Float to Calculate

I'm trying to write a program that will do simple functions however I'm aware of the fact that calculating a float is slower than an calculating an integer.

1) What are some techniques for speeding up these functions? 2) These functions are currently in my void setup() however I'm looking for a way to implement them into the loop by possibly changing the variables using a "for loop". Any advice on how I can create a custom function?

Here is my code:

int potSize = 30; //Size of the pot before the Hero bets. int bet = 15; //Assume the Villain bets ____ amount int raiseTo = 90; //Assume the Hero raises, how much is it to call?

float potOdds = 0.00; potOdds = ((bet + potSize) / bet);

float reversePotOdds = 0.00; reversePotOdds = ((raiseTo + (2 * bet) + potSize) / raiseTo);

I see no functions in that code, or in your duplicate post.

Duplicate post deleted.

Here is my code:

sp. "Here is a fragment of my code:"

What happens if bet is 0?

first how fast should your code minimal be? in other words is timing really a problem? premature optimizations costs a lot of energy and spoil the fun of programming.

that said:

reversePotOdds = ((raiseTo + (2 * bet) + potSize) / raiseTo);

as float division is slower than multiplication you might do

reverseRaiseTo = 1.0 / raiseTo; // assume you need to calculate this not in every iteration

reversePotOdds = ((raiseTo + (2 * bet) + potSize) * reverseRaiseTo );

furthermore do calculations in advance as much as possible and remember the values.

you have to post the whole code to get better answers...

I seriously doubt that the time taken to make these calculations is an issue. I'll wager you have the time to carry out this calculation using an abacus, let alone a microcontroller running at 16Mhz.