# Floating Point Modulus

This is a discussion on Floating Point Modulus within the C Programming forums, part of the General Programming Boards category; Hi, I'm trying to find the modulus of two floating point numbers. I should be able to use fmodf, but ...

1. ## Floating Point Modulus

Hi,
I'm trying to find the modulus of two floating point numbers. I should be able to use fmodf, but I'm getting seemingly random values when I pass it the numerator as a variable.

For example,
Code:
`alpha = fmodf(31, 7);`
returns 3.000000, which is correct, but
Code:
```float theta_demand = 31;
alpha = fmodf(theta_demand, 7);```
returns 6.000000, which makes no sense.

Thanks,
Dave

2. Nope. Here's my test program and output:
Code:
```#include <stdio.h>
#include <math.h>

int main(void)
{
float theta = 31;
float alpha;

alpha = fmodf(31, 7);
printf("Using just literals, alpha = %f\n", alpha);
fmodf(theta, 7);
printf("Using a variable in the numerator, alpha = %f\n", alpha);

return 0;
}```
Code:
```\$ gcc -Wall -o fmod fmod.c -lm
\$ ./fmod
Using just literals, alpha = 3.000000
Using a variable in the numerator, alpha = 3.000000```
Can you give us the smallest possible complete program that shows the differing behavior? Also, what OS, compiler, IDE, etc are you using (names and versions)?

3. I tried your code and got the same results as you. I then realised that I'd used theta_demand (the variable name I was passing to fmodf) as a parameter in the function I was writing, and I was initialising it with the value (31) outside it. Stupid mistake really, but thanks for helping me find it.