L
lloyd
I find this odd:
===========================
#include <stdio.h>
int main(int argc, char *argv[])
{
float phi, phi_start, phi_end, phi_step;
phi_start = 0.0;
phi_end = 3.0;
phi_step = 0.2;
for (phi = phi_start; phi<= phi_end; phi=phi+phi_step)
printf("phi = %.15f\n",phi);
return 0;
}
============================
phi = 0.200000002980232
phi = 0.400000005960464
phi = 0.600000023841858
phi = 0.800000011920929
phi = 1.000000000000000
phi = 1.200000047683716
phi = 1.400000095367432
phi = 1.600000143051147
phi = 1.800000190734863
phi = 2.000000238418579
phi = 2.200000286102295
phi = 2.400000333786011
phi = 2.600000381469727
phi = 2.800000429153442
What the heck is up? It's fine if I set phi_step to 0.25 (I mean you
get the expected values of phi.) The bad digits are further away from
the decimal point if I use doubles instead, but they still are enough
to break a test of "if (phi==floor(phi))" which I want to use so I can
flag cases where phi is an integer. Currently I'm using "if (phi -
floor(phi) < epsilon)" to catch those cases, and I've had to change my
loop condition to "phi<=phi_end+epsilon". What's the usual practice?
===========================
#include <stdio.h>
int main(int argc, char *argv[])
{
float phi, phi_start, phi_end, phi_step;
phi_start = 0.0;
phi_end = 3.0;
phi_step = 0.2;
for (phi = phi_start; phi<= phi_end; phi=phi+phi_step)
printf("phi = %.15f\n",phi);
return 0;
}
============================
phi = 0.000000000000000./test
phi = 0.200000002980232
phi = 0.400000005960464
phi = 0.600000023841858
phi = 0.800000011920929
phi = 1.000000000000000
phi = 1.200000047683716
phi = 1.400000095367432
phi = 1.600000143051147
phi = 1.800000190734863
phi = 2.000000238418579
phi = 2.200000286102295
phi = 2.400000333786011
phi = 2.600000381469727
phi = 2.800000429153442
What the heck is up? It's fine if I set phi_step to 0.25 (I mean you
get the expected values of phi.) The bad digits are further away from
the decimal point if I use doubles instead, but they still are enough
to break a test of "if (phi==floor(phi))" which I want to use so I can
flag cases where phi is an integer. Currently I'm using "if (phi -
floor(phi) < epsilon)" to catch those cases, and I've had to change my
loop condition to "phi<=phi_end+epsilon". What's the usual practice?