division by 1/value

Asked

Viewed 36 times

-2

I’m doing some work that needs complex mathematical equations. And I’m having a problem early on, when I try to do the 1/result split, the answer is always 0,000.

I have tried using double, float, Pow() and the result is the same. (all values are different from 0)

    capacitor = (2*pi*resistor*fc);
    printf("%lf\n", capacitor);
    capacitor = 1/capacitor;
    printf("%lf", capacitor);

Answer: 0.0000

  • 3

    Change of 2 for 2.0 in multiplication solves the problem? Or the 1 for 1.0. I haven’t dealt with C for a long time, but it may be that he’s interpreting the constant as an integer and then the division turns out to be an integer. It talks a little about this: https://answall.com/a/254001/100416

  • 1

    I think it would help to post the whole code because the declaration of variables can influence the question.

  • Write for example capacitor = (2*pi*(double)resistor*fc); and capacitor = 1/(double)capacitor; forcing the compiler to calculate the whole expression as double. And, of course, declare capacitor as such...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.