Dividing with big(ish) numbers in C (Get a zero, when I know it isn't zero)

Lockey

Okay, so I have already proved that the answer is -7.98392238758e-07 in python in about 20 seconds, but why can I not receive the same answer in C (I get zero).

double x = 1255060;
double y = -1571985829941;

double z = x/y;

printf("\nZ is %f", z);

Originally I thought that the issue was that I needed to use a long long instead of a double, but I still receive the same answer of 0.

I am very intrigued to know the solution to this annoying problem.

MatsLindh

The example gives the expected answer (under clang):

Z is -0.000001

(which is the same as -7.98392238758e-07 rounded upwards)

You can use the %e format placeholder in printf to make it use scientific notation, in the same manner as what python uses.

double x = 1255060;
double y = -1571985829941;

double z = x/y;

printf("\nX is %f", x);
printf("\nY is %f", y);
printf("\nZ is %e", z);

Output

X is 1255060.000000
Y is -1571985829941.000000
Z is -7.983914e-07

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

"Divide by zero encountered in log" when not dividing by zero

From Dev

Dividing two numbers always equals zero?

From Dev

Preventing NaN when dividing zero with value

From Dev

Preventing NaN when dividing zero with value

From Dev

Dividing by zero in a constant expression

From Dev

How might I treat nil values as zero when adding numbers?

From Dev

gnuplot: How to get %c zero space for numbers 1-999?

From Dev

Using `SUMPRODUCT` without dividing by zero

From Dev

Dividing by zero with undeclared variable javascript

From Dev

I want to set last three bit to zero,but I don't know where My code wrong?

From Dev

Round very small numbers to zero (c++)

From Dev

How to get a floating point infinity that when multiplied by zero gives zero

From Dev

Anagram in C: How do I know if every element of the int array is set to zero?

From Dev

OpenGL: Why isn't discarding fragments the same as setting their alpha to zero?

From Java

Do I need to explicitly handle negative numbers or zero when summing squared digits?

From Dev

How do I get zero-padded numbers using brace expansion? {1..30} with 01 02 03 etc

From Dev

Dividing float by int and storing as float - Division by zero

From Dev

How to avoid dividing by zero in SQL query?

From Dev

Getting a dividing by zero error on my function

From Dev

Check if dividing by zero, then printing two lines?

From Dev

How do I know an array contains all zero(0) in Javascript

From Dev

Bit shift resulting in zero when it shouldn't

From Dev

Show small numbers as zero

From Dev

replacing of numbers to zero in a sum

From Dev

Replace negative numbers with zero?

From Dev

allow zero numbers with REGEx

From Dev

replacing of numbers to zero in a sum

From Dev

What happens when I divide by zero?

From Dev

How close to division by zero can I get?

Related Related

  1. 1

    "Divide by zero encountered in log" when not dividing by zero

  2. 2

    Dividing two numbers always equals zero?

  3. 3

    Preventing NaN when dividing zero with value

  4. 4

    Preventing NaN when dividing zero with value

  5. 5

    Dividing by zero in a constant expression

  6. 6

    How might I treat nil values as zero when adding numbers?

  7. 7

    gnuplot: How to get %c zero space for numbers 1-999?

  8. 8

    Using `SUMPRODUCT` without dividing by zero

  9. 9

    Dividing by zero with undeclared variable javascript

  10. 10

    I want to set last three bit to zero,but I don't know where My code wrong?

  11. 11

    Round very small numbers to zero (c++)

  12. 12

    How to get a floating point infinity that when multiplied by zero gives zero

  13. 13

    Anagram in C: How do I know if every element of the int array is set to zero?

  14. 14

    OpenGL: Why isn't discarding fragments the same as setting their alpha to zero?

  15. 15

    Do I need to explicitly handle negative numbers or zero when summing squared digits?

  16. 16

    How do I get zero-padded numbers using brace expansion? {1..30} with 01 02 03 etc

  17. 17

    Dividing float by int and storing as float - Division by zero

  18. 18

    How to avoid dividing by zero in SQL query?

  19. 19

    Getting a dividing by zero error on my function

  20. 20

    Check if dividing by zero, then printing two lines?

  21. 21

    How do I know an array contains all zero(0) in Javascript

  22. 22

    Bit shift resulting in zero when it shouldn't

  23. 23

    Show small numbers as zero

  24. 24

    replacing of numbers to zero in a sum

  25. 25

    Replace negative numbers with zero?

  26. 26

    allow zero numbers with REGEx

  27. 27

    replacing of numbers to zero in a sum

  28. 28

    What happens when I divide by zero?

  29. 29

    How close to division by zero can I get?

HotTag

Archive