Rounding double

J

jacob navia

Marco said:
I mean when it comes out of RoundMyDouble
That can't work because (as I said before) long long
has only 18 digits (or similar)

Rounding has no sense with values that large.
 
R

Richard Heathfield

David Harmon said:
On Thu, 22 Nov 2007 09:12:02 +0000 in comp.lang.c++, Richard


But saying that "double &value" is illegal doesn't "work" in c.l.c++

Touche'. :) Nevertheless, agreeing that it's legal doesn't work in clc.
 
J

jacob navia

Richard said:
David Harmon said:


Touche'. :) Nevertheless, agreeing that it's legal doesn't work in clc.

Who cares?

That works in lcc-win.

Lcc-win gives you the best of C and C++
 
J

jacob navia

Richard said:
jacob navia said:


Here is an approximation of pi * (10 to the power 60), that I have
truncated at the sixtieth decimal place.

3141592653589793238462643383279502884197169399375105820974944.
592307816406286208998628034825342117067982148086513282306647

If we round to forty decimal places, we get:

3141592653589793238462643383279502884197169399375105820974944.
5923078164062862089986280348253421170680

What makes you think this "has no sense"?

And you will tell me that you used double precision of course.
 
R

Richard Heathfield

jacob navia said:
That can't work because (as I said before) long long
has only 18 digits (or similar)

Rounding has no sense with values that large.

Here is an approximation of pi * (10 to the power 60), that I have
truncated at the sixtieth decimal place.

3141592653589793238462643383279502884197169399375105820974944.
592307816406286208998628034825342117067982148086513282306647

If we round to forty decimal places, we get:

3141592653589793238462643383279502884197169399375105820974944.
5923078164062862089986280348253421170680

What makes you think this "has no sense"?
 
J

jacob navia

Richard said:
jacob navia said:


People who don't wish to mislead to OP by giving incorrect advice.

<spam snipped>

Incorrect advice happens only when they read your posts.
 
R

Richard Heathfield

jacob navia said:
And you will tell me that you used double precision of course.

I was answering your specific point that "Rounding has no sense with values
that large", by demonstrating that rounding does indeed "have sense" even
with values trillions of times larger. You still have not explained why
you think it "has no sense".

Your latest question is a non sequitur. In any case, C does not place any
upper limit on the precision of double precision floating point values.
 
R

Richard Heathfield

jacob navia said:
Richard said:
jacob navia said:
Richard Heathfield wrote:
David Harmon said:

On Thu, 22 Nov 2007 09:12:02 +0000 in comp.lang.c++, Richard
Right - but of course a cross-posted article should "work" in all
the groups into which it's posted.
But saying that "double &value" is illegal doesn't "work" in c.l.c++
Touche'. :) Nevertheless, agreeing that it's legal doesn't work in
clc.

Who cares?

People who don't wish to mislead [the] OP by giving incorrect advice.

<spam snipped>

Incorrect advice happens only when they read your posts.

Wrong again. I'm not going to argue this point with you, however. If anyone
is silly enough to believe you, that's their problem.
 
J

jacob navia

Richard said:
jacob navia said:


I was answering your specific point that "Rounding has no sense with values
that large", by demonstrating that rounding does indeed "have sense" even
with values trillions of times larger. You still have not explained why
you think it "has no sense".

Your latest question is a non sequitur. In any case, C does not place any
upper limit on the precision of double precision floating point values.

Who is saying anything about "C in general" ???

Can't you read THE SUBJECT OF THIS THREAD!!!
"Rounding double"

You know what DOUBLE means?

This thread is about rounding double precision numbers,
and your multi precision is off topic in this thread!

NOTE THE SUBJECT HEATHFIELD!

It is NOT "rounding in general to 50 decimal places" it
is "Rounding double" OK?
 
W

Walter Roberson

Incorrect advice happens only when they read your posts.

Incorrect advice also happens when people read some of *my* posts,
so your "only" would appear to be incorrect.

I don't know of -any- poster here who has a perfect advice posting
record (though some average much higher quality than others.)
 
J

jacob navia

Walter said:
Incorrect advice also happens when people read some of *my* posts,
so your "only" would appear to be incorrect.

I don't know of -any- poster here who has a perfect advice posting
record (though some average much higher quality than others.)

And there are others that do not give ANY solution,
limiting themselves to say why the solutions presented in some
cases not asked for would not work

I used the original solution and fixed it for double
precision, it is surely not the best solution.

But instead of proposing a better solution this people limit
to talking nonsense without ever proposing anything else.

Then I get angry start getting mad at heathfield and this
degrades.
 
W

Walter Roberson

Can't you read THE SUBJECT OF THIS THREAD!!!
"Rounding double"
You know what DOUBLE means?
This thread is about rounding double precision numbers,
and your multi precision is off topic in this thread!
It is NOT "rounding in general to 50 decimal places" it
is "Rounding double" OK?

"double" is a C datatype defined by the C standards in terms
of *minimum* capacity.

I know of at least one system in which double has a 107 bit mantissa,
which is approximately 34 decimal digits.
 
R

Richard Heathfield

jacob navia said:
Who is saying anything about "C in general" ???

Can't you read THE SUBJECT OF THIS THREAD!!!

Yes, thank you.
"Rounding double"

You know what DOUBLE means?

Presumably you mean "double" rather than "DOUBLE". Yes, I know what it
means, but it appears that you don't.
This thread is about rounding double precision numbers,
and your multi precision is off topic in this thread!

I'm talking about double-precision numbers. You appear to believe that C
specifies a particular precision for double. It does not. It specifies
only a minimum precision that any implementation must provide, but it
imposes no maximum precision. Implementations are free to provide a
thousand digits of precision if they wish, or even more.
NOTE THE SUBJECT HEATHFIELD!

I have done so.
It is NOT "rounding in general to 50 decimal places" it
is "Rounding double" OK?

I am aware of that. What makes you imagine that C forbids 50 or more
decimal places of precision for doubles?
 
J

jacob navia

Richard said:
I'm talking about double-precision numbers. You appear to believe that C
specifies a particular precision for double. It does not. It specifies
only a minimum precision that any implementation must provide, but it
imposes no maximum precision. Implementations are free to provide a
thousand digits of precision if they wish, or even more.


I have done so.


I am aware of that. What makes you imagine that C forbids 50 or more
decimal places of precision for doubles?

I do not know which "C" you are talking about. I am talking about
the C as defined by the C99 standard which says in the
Annex F (normative)

<quote>
The C floating types match the IEC 60559 formats as follows:
— The float type matches the IEC 60559 single format.
— The double type matches the IEC 60559 double format.
<end quote>

That is a quite clearly defined format, defined by IEEE
in 1987 with another name (IEEE754) then generalized to
IEC 60559. This is a 64 bits/53 mantissa etc.

Of course the standard is not a guide for you? Or you are still speaking
about the obsolete 1980 standard?

Which C you are referring to ?
 
J

jacob navia

Walter said:
"double" is a C datatype defined by the C standards in terms
of *minimum* capacity.

I know of at least one system in which double has a 107 bit mantissa,
which is approximately 34 decimal digits.

You are wrong. See Annex F (normative) of the C standard or
my answer to heathfield in this same thread.
 
R

Richard Heathfield

jacob navia said:
And there are others that do not give ANY solution,

Instead, they have given appropriate explanations of why no solution to the
question as asked is possible, and suggestions as to how to deal with this
problem, which is inherent in the general representation of fractions.
limiting themselves to say why the solutions presented in some
cases not asked for would not work

The question as asked is: "Does any body know, how to round a double value
with a specific number of digits after the decimal points?" No specific
cases were asked for, so any criticism of any broken "solution", if it
addresses any cases at all, is bound to address cases not asked for.
I used the original solution and fixed it for double
precision, it is surely not the best solution.

That, at least, is true. The best solution is to understand the inherent
limitations in representing fractions, and to recognise that the
appropriate way to deal with this is to deal with the rounding at the
display stage.
But instead of proposing a better solution this people limit
to talking nonsense without ever proposing anything else.

Ah, we're back to "nonsense" as your synonym for "correct solution that
Jacob Navia doesn't understand", are we?
Then I get angry start getting mad at heathfield and this
degrades.

If you get angry every time you're wrong, you must be angry a *lot*. But
the degradation comes from your posting of incorrect solutions and
misconceptions about C. If you were to take the trouble to learn C
properly, you might find yourself winning more arguments (and getting the
support of others in this newsgroup, instead of constantly facing their
corrections).
 
W

Walter Roberson

I do not know which "C" you are talking about. I am talking about
the C as defined by the C99 standard which says in the
Annex F (normative)
<quote>
The C floating types match the IEC 60559 formats as follows:
— The float type matches the IEC 60559 single format.
— The double type matches the IEC 60559 double format.
<end quote>

You missed the earlier portion of the same Annex:

An implementation
that defines __STDC_IEC_559__ conforms to the specifications
in this annex.

Implementations are not required to define __STDC_IEC_559__
and hence have no mandated maximum limits on the number of double
digits.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top