home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!manuel.anu.edu.au!sserve!prolix!prolix.apana.org.au!dac
- From: dac@prolix.apana.org.au (Andrew Clayton)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Stupid C question
- Message-ID: <ELKcs*YN0@prolix.apana.org.au>
- Date: Mon, 28 Dec 1992 06:27:20 GMT
- References: <ad99s461.037k@sycom.mi.org>
- Distribution: world
- Organization: More like Dis~, really.
- X-Newsreader: Arn V1.00
- Lines: 53
-
- In article <ad99s461.037k@sycom.mi.org>, Alex Deburie writes:
-
- > Okay, I've had SAS-C 6.0 for about 2 weeks and I'm very pleased. Between GST's
- > and the Workbench interface, I doubt I could ask for a better introduction to
- > C on the Amiga.
- >
- > However, I have one very stupid (simple?) question. HOW DOES ONE COVERT A
- > FLOATING POINT VALUE TO AN INTEGER???!!! I see functions like modf(), but
- > still that returns the integral part of the number as a float. And casting
- > seems to always return a 0!
-
- /* My test */
-
- #include <stdio.h>
-
- void
- main(void)
- {
- int fred;
- double joe;
- const int square = 4;
-
- joe = (double)square;
- fred = (int)joe * square;
- printf("Fred %d Joe %f Square %d\n", fred, joe, square);
-
- }
-
- I ran this through the compiler,
-
- SAS/C Amiga Compiler 6.00
- Copyright (c) 1988-1992 SAS Institute Inc.
- Slink - Version 6.00
- Copyright (c) 1992 SAS Institute, Inc. All Rights Reserved.
-
-
- SLINK Complete - Maximum code size = 9032 ($00002348) bytes
-
- Final output file size = 10888 ($00002a88) bytes
-
-
- and running this program produced:
-
- Fred 16 Joe 4.000000 Square 4
-
- Note that you must link with the MATH library in order for
- floating point operations to work.
-
- Dac
- --
- dac@prolix.apana.org.au David Andrew Clayton. // _| _ _
- dac@prolix.sserve.cc.adfa.oz.au Canberra, Australia \X/ (_](_](_
- <Using ARN on an Amiga 4000. Yay!>
-