Is variable a double or long?
Page 1 of 113 Replies - 192 Views - Last Post: 06 October 2012 - 10:09 AM
#1
Is variable a double or long?
Posted 06 October 2012 - 08:52 AM
Thank you very much
Replies To: Is variable a double or long?
#2
Re: Is variable a double or long?
Posted 06 October 2012 - 08:58 AM
Quote
Yes, it can be done by type-casting. Something like
int interger_part = (int)variable; OR int interger_part = (long)variable;
#3
Re: Is variable a double or long?
Posted 06 October 2012 - 09:13 AM
What do you consider "relatively small numbers"?
You may want to study this link: Variables, Data Types.
Jim
#4
Re: Is variable a double or long?
Posted 06 October 2012 - 09:21 AM
When i said relatively small i meant that the test works for say, 12 000 but doesnt for 4 000 000 000...
#5
Re: Is variable a double or long?
Posted 06 October 2012 - 09:29 AM
Jim
This post has been edited by jimblumberg: 06 October 2012 - 09:30 AM
#6
Re: Is variable a double or long?
Posted 06 October 2012 - 09:37 AM
Hmm i just did your test and ended up with 2 147 483 647
how is that possible???
#7
Re: Is variable a double or long?
Posted 06 October 2012 - 09:39 AM
What other limitations are there that you haven't mentioned?
What standard does your teacher require/allow you to use? Pre-C89, C89-90, C99, C11?
Hmm i just did your test and ended up with 2 147 483 647
how is that possible???
Because your compiler is not using 16 bit, it's 32 bit.
Jim
This post has been edited by jimblumberg: 06 October 2012 - 09:39 AM
#8
Re: Is variable a double or long?
Posted 06 October 2012 - 09:39 AM
#9
Re: Is variable a double or long?
Posted 06 October 2012 - 09:45 AM
Jim
#10
Re: Is variable a double or long?
Posted 06 October 2012 - 09:48 AM
#11
Re: Is variable a double or long?
Posted 06 October 2012 - 09:56 AM
#include <iostream>
#include <typeinfo>
using namespace std;
int main()
{
long x;
double y;
float z;
cout << typeid(x).name() << endl;
cout << typeid(y).name() << endl;
cout << typeid(z).name() << endl;
return 0;
}
Anyway, Jim's response in post #5 is the appropriate way to tell if a double value will fit into a long.
#12
Re: Is variable a double or long?
Posted 06 October 2012 - 09:59 AM
Jim
This post has been edited by jimblumberg: 06 October 2012 - 10:00 AM
#13
Re: Is variable a double or long?
Posted 06 October 2012 - 10:08 AM
Thank you for taking the time to answer my questions
#14
Re: Is variable a double or long?
Posted 06 October 2012 - 10:09 AM
Skydiver, on 06 October 2012 - 11:56 AM, said:
#include <iostream> #include <typeinfo> using namespace std; .....
But remember this only works in C++, the OP stated he is using C, C doesn't have this functionality.
Jim
This post has been edited by jimblumberg: 06 October 2012 - 10:10 AM
|
|

New Topic/Question
Reply



MultiQuote




|