Read a double as int

Hello everyone!

How can I interpret a double as if it were a long int, casting of course doesn't help:

1
2
3
4
5
6
int main()
{
    double d = 32.0;
    printf("%f %d", d, (long int) d);
    return 0;
}


This displays 32.000000 and 32 as expected. Also I cannot have a long int point to double.

Any solutions?
Last edited on
You are talking about two different interpretations of a value. The computer can look at the same number and interpret it several ways. You are interpreting a decimal to an integer. I'm not sure what your question is, but you have successfully converted between the two in the given code.
If you are wondering about the pointer, having a integer pointer pointing to a double is like trying to shove a round peg through a square hole. It just doesn't happen. You have to define a double pointer to point to a double.
What I mean:

I want the bit sequence at those 8 bytes reserved for d to be read in the same way a long int is read.
It would appear that you have already done it. Although, you may want to look into unions.
http://www.cplusplus.com/doc/tutorial%20/other_data_types/
Yupp, that's what I'm looking for.

Many thanks!
Topic archived. No new replies allowed.