www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/03/23:50:09

From: gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Floating point accuracy
Date: 3 Mar 1997 23:45:11 GMT
Organization: Oxford University
Lines: 19
Message-ID: <5ffnq7$c2p@news.ox.ac.uk>
References: <5ff7e6$974 AT cronkite DOT ocis DOT temple DOT edu>
NNTP-Posting-Host: mc31.merton.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

David Tucker (david AT temss2 DOT main DOT temple DOT edu) 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.

The integer result is indeed 0 - you can't fit any '1000's into a '994'.
If you are interested in the real result, cast to float (or double for
more accuracy) before dividing. Make sure X is of a floating-point type, 
though.

-- 
George Foot <gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk>
Merton College, Oxford.

- Raw text -


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