long double collect_dust(long double last_mass, long double *new_dust, long double *new_gas, long double a, long double e, long double crit_mass, dust_pointer dust_band) { long double mass_density; long double temp1; long double temp2; long double temp; long double temp_density; long double bandwidth; long double width; long double volume; long double gas_density = 0.0; long double new_mass; long double next_mass; long double next_dust = 0; long double next_gas = 0; printf ("\nStart crit_mass :%.2LE\n",crit_mass); temp = last_mass / (1.0 + last_mass); printf ("Modified temp:%.2LE\n",temp ); reduced_mass = pow(temp,(1.0 / 4.0)); printf ("reduced_mass:%.2LE\n",reduced_mass ); if ( !temp ) exit (1); r_inner = inner_effect_limit(a, e, reduced_mass); r_outer = outer_effect_limit(a, e, reduced_mass); if ((r_inner < 0.0)) r_inner = 0.0; if ((dust_band == NULL)){ printf("dustband Null\n"); return(0); } else { if ((dust_band->dust_present == FALSE)) temp_density = 0.0; else temp_density = dust_density; if (((last_mass < crit_mass) || (dust_band->gas_present == FALSE))){ mass_density = temp_density; printf(" mass_density %LE = temp_density %LE \n",mass_density,temp_density); } else { printf("line 84\n"); mass_density = K * temp_density / (1.0 + sqrt(crit_mass / last_mass) * (K - 1.0)); printf(" mass_density %LE \n temp_density %LE \n crit_mass %LE \n last_mass %LE \n K %LE \n " , mass_density , temp_density, crit_mass, last_mass, K ); printf(" mass_density %LE = temp_density %LE \n",mass_density,temp_density); gas_density = mass_density - temp_density; } if (((dust_band->outer_edge <= r_inner) || (dust_band->inner_edge >= r_outer))) { printf ("CD1 Last Mass :%.2LE\n",last_mass ); return(collect_dust(last_mass, new_dust, new_gas, a,e,crit_mass, dust_band->next_band)); } else { bandwidth = (r_outer - r_inner); temp1 = r_outer - dust_band->outer_edge; if (temp1 < 0.0) temp1 = 0.0; width = bandwidth - temp1; temp2 = dust_band->inner_edge - r_inner; if (temp2 < 0.0) temp2 = 0.0; width = width - temp2; temp = 4.0 * PI * pow(a,2.0) * reduced_mass * (1.0 - e * (temp1 - temp2) / bandwidth); printf ( "start volume: %LE \n",volume ); volume = temp * width; printf ( "End volume: %LE \n",volume ); new_mass = volume * mass_density; printf ( " Volume: %LE * mass_density: %LE = new_mass : %LE \n", volume , mass_density , new_mass ); *new_gas = volume * gas_density; *new_dust = new_mass - *new_gas; printf ("CD2 Last Mass :%.2LE\n",last_mass ); next_mass = collect_dust(last_mass, &next_dust, &next_gas, a,e,crit_mass, dust_band->next_band); printf ("CD2 Next Mass :%.2LE\n",next_mass ); *new_gas = *new_gas + next_gas; printf ("End return newmass: %LE + Next_mass :%LE = %LE \n" , new_mass , next_mass , new_mass + next_mass ); return(new_mass + next_mass); } } } compiled using gcc 4.0.3 Description of behavior the var crit_mass is passed to this function with the value NaN, if i print it on line ## then function runs fine, if I do not print it the NaN value transfers to other vars and causes a infinit loop. This seems very starnge behavior. Any suggestions as to what might be causing this?