home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / arch / 10751 < prev    next >
Encoding:
Internet Message Format  |  1992-11-15  |  1.7 KB

  1. Xref: sparky comp.arch:10751 comp.lang.misc:3693
  2. Path: sparky!uunet!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!tmb
  3. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  4. Newsgroups: comp.arch,comp.lang.misc
  5. Subject: Re: how to advocate new software/hardware features (Re: Hardware Support for Numeric Algorithms)
  6. Date: 15 Nov 92 21:30:27
  7. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  8.     Perceptive)
  9. Lines: 35
  10. Message-ID: <TMB.92Nov15213027@arolla.idiap.ch>
  11. References: <1992Nov10.153705.27804@yrloc.ipsa.reuter.COM>
  12.     <1992Nov12.131856.12605@linus.mitre.org>
  13.     <TMB.92Nov13144057@arolla.idiap.ch>
  14.     <1992Nov13.155126.3660@linus.mitre.org>
  15.     <TMB.92Nov14145619@pollux.idiap.ch>
  16. Reply-To: tmb@idiap.ch
  17. NNTP-Posting-Host: arolla.idiap.ch
  18. In-reply-to: tmb@pollux.idiap.ch's message of 14 Nov 92 14:56:19
  19.  
  20. In article <TMB.92Nov14145619@pollux.idiap.ch> tmb@pollux.idiap.ch (Thomas M. Breuel) writes:
  21.  
  22.        Even the C language has provisions for just the case that you are
  23.        concerned with in the case of 16bit integers, 32bit longs:
  24.  
  25.        int a = ...;
  26.        int b = ...;
  27.        int c = ...;
  28.        long product = a*b;
  29.        int result = product/c;
  30.  
  31.        In fact, on some machines, int is 32bit and long is 64bit,
  32.        so this code will do what you want.
  33.  
  34.        Furthermore, C is being extended to allow access to 64bit types,
  35.        so that you can write:
  36.  
  37.        int a = ...;
  38.        int b = ...;
  39.        long long product = a*b;
  40.        int result = product/c;
  41.  
  42. Oops, that should, of course have been:
  43.  
  44.    long product = (long)a*(long)b;
  45.  
  46. and
  47.  
  48.    long long product = (long long)a*(long long)b;
  49.  
  50. Now, _my_ pet peeve with C is that this bug would have gone
  51. undetected... (a compiler should warn about the lack of a conversion,
  52. and a runtime system should catch any overflow).
  53.  
  54.                     Thomas.
  55.