home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 1212 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  93 lines

  1. Path: shell1.eznet.net!not-for-mail
  2. From: armstron@eznet.net (Jon Armstrong)
  3. Newsgroups: comp.sys.amiga.programmer,uiuc.class.cs110c,uiuc.class.cs223
  4. Subject: Re: How do I define my integers?
  5. Date: 15 Jan 1996 22:25:16 -0500
  6. Organization: E-Znet, Incorporated, Rochester, NY 14604 (716)-262-2485
  7. Message-ID: <4df5qs$sg6@shell1.eznet.net>
  8. References: <4d73ug$25v@vixen.cso.uiuc.edu>
  9. NNTP-Posting-Host: shell1.eznet.net
  10.  
  11. In article <4d73ug$25v@vixen.cso.uiuc.edu>,
  12. howard daniel joseph <djhoward@ux5.cso.uiuc.edu> wrote:
  13.  
  14. >How do I declare signed versus unsigned integers?
  15.  
  16. int i;           /* This is a signed integer    */
  17. unsigned int u;  /* This is an unsigned integer */
  18.  
  19. >How do I know how many bits my integers are using?
  20.  
  21. Look in <machine/limits.h>
  22.  
  23. You will find defines for SHORTBITS, INTBITS, LONGBITS, etc.
  24. They use the sizeof() built-in feature of C.
  25.  
  26. >How do I declare signed and unsigned long integers?
  27.  
  28. long l;
  29. unsigned long ul;
  30.  
  31. >What's with these "doubles" the book mysteriously alludes to?
  32.  
  33. float f;   /* This is a floating point number */
  34. double d;  /* This is a double precision floating point number */
  35.  
  36. These types allow the representation and manipulation of fractional
  37. (real) numbers, like 3.14159265, etc.
  38.  
  39. >What *am* I creating when I type;
  40. >
  41. >int somevalue;
  42.  
  43. It's a signed integer, which is sizeof(int) bytes in size.  Normally
  44. 4 bytes or 32 bits on a current Amiga.
  45.  
  46. #include <machine/limits.h>
  47.  
  48. int main()
  49. {
  50.   printf("INTBITS = %d\n",INTBITS);
  51.   return 0;
  52. }
  53.  
  54. Result:
  55.  
  56. INTBITS = 32
  57.  
  58. >An integer (unsigned) that can handle, 6, though ideally 9 places (Just 
  59. >under 250000000 would be the maximum forseen possible value here.)
  60.  
  61. printf("ULONG_MAX = %u\n",ULONG_MAX);
  62.  
  63. ULONG_MAX = 4294967295
  64.  
  65. >An integer that can handle a much bigger number ... 12 places at least for 
  66. >now.
  67.  
  68. You don't say signed or unsigned, so I'll assume unsigned.
  69.  
  70. I don't believe there currently exists an elementary type to handle
  71. this case on the Amiga with GCC.  You'd have to find a suitable
  72. library for this or write your own set of routines to handle a type
  73. like...
  74.  
  75. typedef struct { unsigned long high; unsigned long low; } large_t;
  76.  
  77. Alternatively, you might consider using a double, which is 8 bytes
  78. in size (mantissa/exponent/etc), but is a real, not an integer type.
  79.  
  80. I believe the type .. long long .. or similar may be coming along in
  81. the near future, but it's not quite here, yet.  You may find it on
  82. certain platforms with certain compilers.
  83.  
  84. >Can I perform simple maths (addition, division) between integers of 
  85. >different types? I'd assume so, right?
  86.  
  87. Yes.
  88.  
  89. -- 
  90.                +----------------------------------------------+
  91. Regards... Jon | Armstrong | LPA Software, Inc. | jma@lpa.com |
  92.                +----------------------------------------------+
  93.