Re: Rounding a floating point number
- From: "Bartc" <bc@xxxxxxxxxx>
- Date: Thu, 28 Feb 2008 01:47:03 GMT
"CBFalconer" <cbfalconer@xxxxxxxxx> wrote in message
news:47C58B78.4F05267@xxxxxxxxxxxx
user923005 wrote:
CBFalconer <cbfalco...@xxxxxxxxx> wrote:
user923005 wrote:
... snip float rounding discussion ...
You will still have to multiply and divide by powers of 10 and
use floor() to achieve the same thing because the C99 round()
functions round to nearest integer. They do not round to
nearest k decimal places.
Are you claiming that such multiplication and division by 10 is
too complex for the average reader of c.l.c? :-)
No, but I am claiming that using the C99 functions to round to N
digits will take twice as much work as a function that does it
directly, since the multiplication and division by a power of
ten and the floor function are all that is necessary in either
case. And so while you can round to N digits using the C99
rounding functions, it really does not make a lot of sense to do
it that way.
Let me also point out that such rounding is rarely needed. Most of
the time maintaining the original alleged precision and rounding
only the output, via printf, is needed.
There was a long discussion about this stuff last November in c.l.c with
various examples of why such rounding can be useful. One example was
cleaning noisy data.
--
Bart
.
- References:
- Rounding a floating point number
- From: jacob navia
- Re: Rounding a floating point number
- From: CBFalconer
- Re: Rounding a floating point number
- From: Ben Pfaff
- Re: Rounding a floating point number
- From: Keith Thompson
- Re: Rounding a floating point number
- From: user923005
- Re: Rounding a floating point number
- From: CBFalconer
- Re: Rounding a floating point number
- From: user923005
- Re: Rounding a floating point number
- From: CBFalconer
- Rounding a floating point number
- Prev by Date: Re: Why not provide a standard non-busy waiting method?
- Next by Date: Re: Freeing memory - will it be available immediately
- Previous by thread: Re: Rounding a floating point number
- Next by thread: Calling C++ functions in C function through function pointers
- Index(es):
Relevant Pages
|