delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/09/01:00:02

From: Tudor <tudor AT cam DOT org>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Floating point accuracy
Date: Sat, 08 Mar 1997 15:21:12 -0800
Organization: Communications Accesibles Montreal
Lines: 23
Message-ID: <3321F468.3E6B@cam.org>
References: <5ff7e6$974 AT cronkite DOT ocis DOT temple DOT edu>
Reply-To: tudor AT cam DOT org
NNTP-Posting-Host: dynappp-50.hip.cam.org
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

David Tucker wrote:
> 
> I have a question.
> 
> When I do a calculation such as:
> 
>         X = a / b; // where int a = 994 and int b = 1000
>                 or
>         cout << "X = " << a / b << endl;
> 
> my result is 0.
> 
> Does anyone know why this happens?
You have them as ints. (int) 5 / (int) 2 != 2.5
If you want floating point make them floats or doubles 
> Thank in advance...
> 
> David

-- 
tudor 'at' cam 'dot' org
http://www.cam.org/~tudor
'This is Scott Nudds of the Borg. C is irrelevant.'

- Raw text -


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