I was trying to plot a function in GNU plot, and my plot kept differing from the one in the paper. Upon reading that GNU interprets functions as C would, I tried coding the function in C. Same problem.
Eventually I figured out the problem could be exhibited with this tidbit:
#include <stdio.h>
#include <stdlib.h>
int main()
{
double p = 1.0;
double pMinusOneHalf1 = p - (1.0/2.0);
double pMinusOneHalf2 = p - (1/2);
printf("\nFirst = %lf \n Second = %lf\n\n", pMinusOneHalf1, pMinusOneHalf2);
return 0;
}
which gives output
First = 0.500000
Second = 1.000000
Just wondering if anyone has an explanation as to why C would assume “1” and “2” as INTs inside of the expression for a DOUBLE.
Seems like a very easy thing for people to get caught on. gcc’s -Wall option doesn’t even comment on it.
/doesn’t particularly care that its result is being subtracted from adouble.All it knows is that it’s given two integers, so it gives you back an integer.