Re: Division in loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <glynn@xxxxxxxxxxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux