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 .
You need to use floats for the line
So instead do
If
samplesPerPeriodis anint, then the division will be integer division. Which means you’re really doingwhich, as an
int, is0which is then converted to afloatwith value0.0. So you’ll need to castsamplesPerPeriodto a float before the division, and to be safe and clear, use afloatvalue of44.0in the denominator as well.