سؤال

I want to use the natural logaritm in c-language.

I searched google and found a question of this at stackoverflow.com

But When I implement this I get a very cryptic output

here is the code

 double x = log(100 / 150);

 printf("d1: %lf", x);

and the output:

 d1: -1.#INF00

What is this? Is it some kind of garbage? What is wrong?

هل كانت مفيدة؟

المحلول

Integer division makes 100 / 150 equal to 0, therefore, log(0) is not defined.

Change the code to log(100.0 / 150.0).

نصائح أخرى

If the parameter to log is 0, the output is implementation defined.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top