| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: c++ help |
From: John Beckett "Geo" wrote in message news:: > Are you sure it's not just stored as an int? I mean if it's integer math > then how would it handle this > > int n = (rand()/32767)*9999999999999 > > That shouldn't generate a cpu error, the error would come when it goes to > store a multibyte value in a single byte location (or maybe at compile > time?) I don't follow your meaning. If you intend that the "9999999999999" is too large for an int, the compiler would assume it is a long int. If the value is too large for a long int, In Visual C++, int and long int are the same (32 bits), and one more step is added to the above. The compiler next tries to fit the value into a 64-bit integer (__int64). If not successful, the compiler gives a warning (or maybe an error in some situations?). A C/C++ compiler won't ever take an integer value (9999999999999) and represent it as a float or double (unless you ask it to do that). By contrast, VB *will* freely convert stuff to whatever it feels like. At any rate, rand() is an int, and the other values in your expression were also ints (or longer). Therefore, int operations (or longer integer operations) will be performed. Consider: double x = sqrt(2); int a = x; // compile error int b = (int)x; You can't literally put x in a (x uses maybe a 64-bit floating-point code, and a uses maybe a 32-bit binary code). However, if you use the cast, as in '(int)x', you ask the compiler to generate code that will convert x to an int. The result will discard the fractional digits, keeping only the integer part. In this case, b == 1. John --- BBBS/NT v4.01 Flag-5* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45) SEEN-BY: 633/267 270 5030/786 @PATH: 379/45 1 396/45 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.