(1/i)
i
is an int
, so that’s integer division, resulting in 0 if i > 1
. Use 1.0/i
to get floating point division.
More Related Contents:
- problems in floating point comparison [duplicate]
- C – Serialization of the floating point numbers (floats, doubles)
- Comparing float and double
- error: incompatible types for a function that returns float in C
- How to convert an int to string in C?
- How do I restrict a float value to only two places after the decimal point in C?
- Is there any way to compute the width of an integer type at compile-time?
- How to represent FLOAT number in memory in C
- Catch and compute overflow during multiplication of two large integers
- What do numbers using 0x notation mean?
- SIMD signed with unsigned multiplication for 64-bit * 64-bit to 128-bit
- What is the instruction that gives branchless FP min and max on x86?
- Is the behaviour of casting a negative double to unsigned int defined in the C standard? Different behaviour on ARM vs. x86
- How do you store an arbitrarily large integer value in memory?
- Checking if float is an integer
- What happens to a float variable when %d is used in a printf?
- Why do we define INT_MIN as -INT_MAX – 1? [duplicate]
- What is the fastest way to convert float to int on x86
- Why does adding a small float to a large float just drop the small one?
- How does printf and co differentiate between float and double
- Can I make gcc tell me when a calculation results in NaN or inf at runtime?
- Status of __STDC_IEC_559__ with modern C compilers
- Is fmod() exact when y is an integer?
- Why does “memset(arr, -1, sizeof(arr)/sizeof(int))” not clear an integer array to -1?
- How can I convert an int to a string in C?
- Trouble with float on C [duplicate]
- Is there any reason not to use fixed width integer types (e.g. uint8_t)?
- When does underflow occur?
- C usual arithmetic conversions
- C printf using %d and %f