home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / amiga / programm / 17912 < prev    next >
Encoding:
Text File  |  1992-12-29  |  1.3 KB  |  40 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!gatech!concert!sas!mozart.unx.sas.com!walker
  3. From: walker@twix.unx.sas.com (Doug Walker)
  4. Subject: Re: Stupid C question
  5. Originator: walker@twix.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <C01C2K.AxK@unx.sas.com>
  8. Date: Tue, 29 Dec 1992 19:13:32 GMT
  9. References:  <ad99s461.037k@sycom.mi.org>
  10. Nntp-Posting-Host: twix.unx.sas.com
  11. Organization: SAS Institute Inc.
  12. Lines: 26
  13.  
  14.  
  15. You say casting always seems to return a zero... I would need
  16. to see your code to find out why.  Is your floating point number
  17. greater than 1.0 in any case?  The following code should do 
  18. what you want:
  19.  
  20. ...
  21.    double x;
  22.    int i, j;
  23. ...
  24.    i = (int)x;       /* Convert with truncation */
  25. ...
  26.    j = (int)(x+0.5); /* Convert with rounding */
  27.  
  28. In the above examples, if "x" is 0.3, you'll get 0 for both
  29. "i" and "j".  If "x" is 0.7, you'll get 0 for "i" but 1 for "j".
  30.  
  31. -- 
  32.   *****
  33. =*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
  34.  *|. o.| ||                                          1200/2400/9600 Dual
  35.   | o  |//     For all you do, this bug's for you!
  36.   ====== 
  37. usenet: walker@unx.sas.com                            bix: djwalker 
  38. Any opinions expressed are mine, not those of SAS Institute, Inc.
  39.  
  40.