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

  1. Path: sparky!uunet!munnari.oz.au!manuel.anu.edu.au!sserve!prolix!prolix.apana.org.au!dac
  2. From: dac@prolix.apana.org.au (Andrew Clayton)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Stupid C question
  5. Message-ID: <ELKcs*YN0@prolix.apana.org.au>
  6. Date: Mon, 28 Dec 1992 06:27:20 GMT
  7. References: <ad99s461.037k@sycom.mi.org>
  8. Distribution: world
  9. Organization: More like Dis~, really.
  10. X-Newsreader: Arn V1.00
  11. Lines: 53
  12.  
  13. In article <ad99s461.037k@sycom.mi.org>, Alex Deburie writes:
  14.  
  15. > Okay, I've had SAS-C 6.0 for about 2 weeks and I'm very pleased. Between GST's 
  16. > and the Workbench interface, I doubt I could ask for a better introduction to 
  17. > C on the Amiga.
  18. > However, I have one very stupid (simple?) question. HOW DOES ONE COVERT A 
  19. > FLOATING POINT VALUE TO AN INTEGER???!!!  I see functions like modf(), but 
  20. > still that returns the integral part of the number as a float. And casting 
  21. > seems to always return a 0!
  22.  
  23. /* My test */
  24.  
  25. #include <stdio.h>
  26.  
  27. void
  28. main(void)
  29. {
  30.     int fred;
  31.     double joe;
  32.     const int square = 4;
  33.  
  34.     joe = (double)square;
  35.     fred = (int)joe * square;
  36.     printf("Fred %d Joe %f Square %d\n", fred, joe, square);
  37.  
  38. }
  39.  
  40. I ran this through the compiler, 
  41.  
  42. SAS/C Amiga Compiler 6.00                                         
  43. Copyright (c) 1988-1992 SAS Institute Inc.                        
  44. Slink - Version 6.00                                              
  45. Copyright (c) 1992 SAS Institute, Inc.  All Rights Reserved.      
  46.                                                                   
  47.                                                                   
  48. SLINK Complete - Maximum code size = 9032 ($00002348) bytes       
  49.                                                                   
  50. Final output file size = 10888 ($00002a88) bytes
  51.  
  52.  
  53. and running this program produced:
  54.  
  55. Fred 16 Joe 4.000000 Square 4
  56.  
  57. Note that you must link with the MATH library in order for
  58. floating point operations to work.
  59.  
  60. Dac
  61. --
  62. dac@prolix.apana.org.au              David Andrew Clayton.           // _| _  _
  63. dac@prolix.sserve.cc.adfa.oz.au      Canberra, Australia           \X/ (_](_](_
  64.                     <Using ARN on an Amiga 4000. Yay!>
  65.