| | |
(very) simple math not working perhaps due to to large numbers?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 111
Reputation:
Solved Threads: 3
Hi again, first; i realise this peace of code is stupid, it has been taken out of context, altered for the sake of simplicity etc.
I wonder if the problem is the quite large number stored in int to (changed to unsigned long int)
i have read on cplusplus.com that even a signed int should be enough though? (i think?) but i believe this varies from compiler to compiler (or is it just from system to system?)
here goes.
the output is just increasing numbers until 2147483648 and from there on it's just zeros?
I wonder if the problem is the quite large number stored in int to (changed to unsigned long int)
i have read on cplusplus.com that even a signed int should be enough though? (i think?) but i believe this varies from compiler to compiler (or is it just from system to system?)
here goes.
c++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int udregn (int tal); int main() { unsigned long int to=2; for (int i=0;i<64;i=i+1) { to = to*2; cout<< to <<endl; } cout<< to <<"hej"; return 0; }
the output is just increasing numbers until 2147483648 and from there on it's just zeros?
Yo god, where do i report a bug?
•
•
Join Date: Mar 2008
Posts: 1,400
Reputation:
Solved Threads: 113
Basically, inside the limits.h file, there will be lots of macros which define the maximum value for many different data types, It would look something like this. You don't have to worry about all that, but as you are using the data type unsigned long int and want to know the maximum value it holds, the maximum value will be defined as ULONG_MAX like MosaicFuneral said. If this data type isn't big enough for you, try using a larger one like unsigned long long (with ULLONG_MAX as the macro containing it's maximum possible value).
Hope this helps clear things up for you.
C++ Syntax (Toggle Plain Text)
#define MB_LEN_MAX 5 /* max. # bytes in multibyte char */ #define SHRT_MIN (-32768) /* minimum (signed) short value */ #define SHRT_MAX 32767 /* maximum (signed) short value */ #define USHRT_MAX 0xffff /* maximum unsigned short value */ #define INT_MIN (-2147483647 - 1) /* minimum (signed) int value */ #define INT_MAX 2147483647 /* maximum (signed) int value */ #define UINT_MAX 0xffffffff /* maximum unsigned int value */ #define LONG_MIN (-2147483647L - 1) /* minimum (signed) long value */ #define LONG_MAX 2147483647L /* maximum (signed) long value */ #define ULONG_MAX 0xffffffffUL /* maximum unsigned long value */ #define LLONG_MAX 9223372036854775807i64 /* maximum signed long long int value */ #define LLONG_MIN (-9223372036854775807i64 - 1) /* minimum signed long long int value */ #define ULLONG_MAX 0xffffffffffffffffui64 /* maximum unsigned long long int value */
Hope this helps clear things up for you.
Last edited by William Hemsworth; Jan 12th, 2009 at 4:48 pm.
•
•
Join Date: Dec 2008
Posts: 111
Reputation:
Solved Threads: 3
Hmm thanks both of you. Certainly cleared out some things for me. for some reason my long_max is only 1 larger than ulong_max. this is for my "transportable" IDE (i have installet it on a USB stick, thats all) that might have something to do with it?
can i just change those values? either just by editing limits.h or by changing the value for a specific program? or can i make a variable of unlimmited size? i believe i have seen something about foo in that context, but i am unable to find it again??
can i just change those values? either just by editing limits.h or by changing the value for a specific program? or can i make a variable of unlimmited size? i believe i have seen something about foo in that context, but i am unable to find it again??
Yo god, where do i report a bug?
![]() |
Other Threads in the C++ Forum
- Previous Thread: Moving the mouse cursor
- Next Thread: need some guidance
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






