www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/21/05:44:01

From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: list of djgpp compiler errors wanted!
Date: 21 Nov 1996 03:51:35 GMT
Organization: Oxford University, England
Lines: 49
Message-ID: <570jk7$4ji@news.ox.ac.uk>
References: <32905cab DOT 10273409 AT news DOT uu DOT se> <19961120 DOT 153203 DOT 14446 DOT 0 DOT MSnakes AT juno DOT com>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Matt J Reiferson (msnakes AT juno DOT com) wrote:
: >int auks;                                                  
: >auks = 19.99 + 11.99;                             

: change your code to one of these:

: float auks;
: auks = 19.99 + 11.99;

: or

: int auks;
: auks = (float)(19.99 + 11.99);

Wrong. This just changes the warning to one about an implicit cast from 
float to int. I believe you meant:

int auks;
auks = (int) (19.99 + 11.99);

This rounds down by default, I believe; IMHO it's better to first use 
either floor or ceil to specify the rounding explicitly, i.e.:

int auks = (int) floor(19.99 + 11.99);

gives the above result (31), whereas

int auks = (int) ceil(19.99 + 11.99);

gives the lowest integer greater than or equal to the result, i.e. 32. If
you want to round it to the nearest (rounding halves up, i.e. 1.5 => 2),
use: 

int auks = (int) floor(19.99 + 11.99 + 0.5);

which, of course, also gives 32. The typecasts to int are still required; 
these functions return doubles. You also need to #include <math.h> before 
using them.

I hope this clears up any misunderstanding.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ |""""""""""""""""""""""|
>Email: george DOT foot AT merton DOT ox DOT ac DOT uk      < |Snail Mail:(*)        |
>   or: mert0407 AT sable DOT ox DOT ac DOT uk          < | _     George Foot    |
>  Web: http://users.ox.ac.uk/~mert0407/ < |(@)    Merton College |
>  Ftp: mc31.merton.ox.ac.uk (#)         < |~~~~   Oxford OX1 4JD |
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ |______________________|
(#) Theoretically...    ||    (*) Please allow 28 days for delivery

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019