S
Sisyphus
Hi,
I have some software that does the following (in an attempt to determine
whether the double x, can be represented just as accurately by a float):
void test_it(double x) {
float y = x;
if(x == y) {
printf("x can be represented precisely by a float\n");
}
else {
printf("x can't be represented precisely by a float\n");
}
}
Is this an acceptable way of determining whether the double can be
represented precisely by a float ? Is there some other (perhaps
preferable) way of doing it ?
One problem is that, with the above function, Microsoft compilers tell
you that x==y, no matter what the value of x. That strikes me as being
quite bizarre.
I'm wondering whether, to make the code portable, I should trick MS
compilers into doing what I think is right (which can be done fairly
simply) - or whether I should be concentrating on applying some other
method.
Thing is that I don't want to stuff around with getting that code to
work properly with MS compilers if the whole concept of that code is of
dubious merit to begin with.
Cheers,
Rob
I have some software that does the following (in an attempt to determine
whether the double x, can be represented just as accurately by a float):
void test_it(double x) {
float y = x;
if(x == y) {
printf("x can be represented precisely by a float\n");
}
else {
printf("x can't be represented precisely by a float\n");
}
}
Is this an acceptable way of determining whether the double can be
represented precisely by a float ? Is there some other (perhaps
preferable) way of doing it ?
One problem is that, with the above function, Microsoft compilers tell
you that x==y, no matter what the value of x. That strikes me as being
quite bizarre.
I'm wondering whether, to make the code portable, I should trick MS
compilers into doing what I think is right (which can be done fairly
simply) - or whether I should be concentrating on applying some other
method.
Thing is that I don't want to stuff around with getting that code to
work properly with MS compilers if the whole concept of that code is of
dubious merit to begin with.
Cheers,
Rob