Re: Division in loop

Glynn Clements <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
Tim Walberg wrote:

> Maybe you want "(bytes * 100) / size"?

However, if int and size_t are 32-bit, that will overflow at around
20 or 40 MB (20 for signed, 40 for unsigned), which isn't really all
that much. Converting to either double or long long might be wise,
i.e.

	percent = (int)(bytes * 100.0) / size;
or:
	percent = (int)(bytes * 100LL) / size;

-- 
Glynn Clements <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.