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

*From*: "Mikkel L. Ellertson" <mikkel infinity-ltd com>*To*: For users of Fedora Core releases <fedora-list redhat com>*Subject*: Re: BASH question*Date*: Fri, 08 Sep 2006 17:02:52 -0500

Aaron Konstam wrote: > Well I am willing to learn but I am unaware that Pentium cpu-s have any way to represent numbers > with fractional parts other than floating point. So there is no such thing as fixed point representation of > non-integer numbers on these machines. > > In addition I have not found any way to have dc deal with non-integers but that may be I am > missing something. > One way this is done, if you are after a fixed number of decimal points, is to simply shift the decimal point over, do the math as an integer, and shift the decimal point back to present the results. It is integer math, but with fractional parts. It works well for doing things like adding, and subtracting things like currency where you have a fixed number of places after the decimal point. When doing multiplication and devision, you can run into rounding errors, depending on how it is implemented. I believe bc truncates results from divide and multiply operations, instead of rounding them. Mikkel -- Do not meddle in the affairs of dragons, for thou art crunchy and taste good with Ketchup!

**References**:**Re: BASH question***From:*Cameron Simpson

**Re: BASH question***From:*Aaron Konstam

**Re: BASH question***From:*Sjoerd Mullender

**Re: BASH question***From:*Aaron Konstam