Q:

infinite when dividing by a float which is smaller than 1?

i have this code :
 float f;
    float time;
    time=samplesPerPeriod/44;
    f=(1/time)*1000;

when samplesPerPeriod is 35 i get infinite in this log:
NSLog(@"frequency:%f Hz",f);

cant i dividing in a number which is smaller then 1 ?
is it have to do with the fact that this is a c function in objective c class ?
thanks .

A:

You need to use floats for the line
time=samplesPerPeriod/44;

So instead do
time=(float)samplesPerPeriod/44.0;

If samplesPerPeriod is an int, then the division will be integer division. Which means you're really doing
35/40

which, as an int, is 0 which is then converted to a float with value 0.0. So you'll need to cast samplesPerPeriod to a float before the division, and to be safe and clear, use a float value of 44.0 in the denominator as well.

