www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/14/13:56:52

From: "Marp" <Marp AT 0 DOT 0 DOT 0 DOT 0>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: float is not working
Date: Wed, 14 Apr 1999 13:30:40 -0400
Organization: Netcom
Lines: 19
Message-ID: <7f2jbu$hkd@dfw-ixnews10.ix.netcom.com>
References: <3714C932 DOT 1E5E452B AT spektracom DOT de>
NNTP-Posting-Host: prn-nj3-04.ix.netcom.com
X-NETCOM-Date: Wed Apr 14 12:30:38 PM CDT 1999
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2014.211
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Andrej Aderhold <dra AT spektracom DOT de> wrote in message
news:3714C932 DOT 1E5E452B AT spektracom DOT de...
> why is this not working ??
>
> float m = 1 / 2;
>
> (m will be 0)
>
> thanks.
> Andrej
>

C uses the smallest datatype to acurately hold data. The numbers 1 and 2 are
integers and so C will do integer division on 1/2 which is less than 1 so m
will hold 0. To get it to hold 0.5 you need to say float m = 1.0 / 2.0, or
typecast it like this: float m = (float)1 / (float)2 Hope this helps you
understand better.


- Raw text -


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