Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: rounding the minimum of a negative number


From   annoporci <annoporci@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: rounding the minimum of a negative number
Date   Thu, 10 Jan 2013 22:34:42 +0800

Thanks Nick, will follow up on the reference.

P.S. yes I did accidentally omit a minus sign.


On Thu, 10 Jan 2013 22:32:01 +0800, Nick Cox <njcoxstata@gmail.com> wrote:

You say that

if Stata had
displayed something like

-1.980000009999

for 1.9810, I would not have been puzzled.

I would have been puzzled to see that. Minus sign aside,
1.980000009999 does not round to 1.9810 under any rule.

We can match ignorance. I have never used Python, but it does not make
any sense to talk about the "true" decimal value of 0.1 or even of the
binary representation that any language uses for 0.1.

The short answer to your last question is, I believe, no.

Otherwise do read William Gould's blog entry.

Nick

On Thu, Jan 10, 2013 at 2:19 PM, annoporci <annoporci@gmail.com> wrote:
Thanks Nick for these precisions.


If you want _display_ to a fixed number of decimal places, that is
ultimately a question of formatting and not a problem of numerics.


Yes. I guess another way of expressing my puzzlement is that Stata does
not display, by default, to a greater number of decimal places.

I don't know anything about this, but in Python, for instance, according
to the documentation: "On a typical machine running Python, there are 53
bits of precision available for a Python float." And, to quote more:

If Python were to print the true decimal value of the binary approximation
stored for 0.1, it would have to display:

0.1000000000000000055511151231257827021181583404541015625

So that's still quite a few zeros after the first 1. And if Stata had
displayed something like

-1.980000009999

for 1.9810, I would not have been puzzled.

I do have one last question and then I'll consider the matter closed:

Would I get a more accurate approximation of "-1.981" with Stata if I
input "-1.981000000001" than if I input "-1.981" ? in the sense that it
would "force" Stata to store the zeros after 981? (or am I
misunderstanding the whole issue?)

Thanks Nick,

--
Patrick Toche.

References:
http://docs.python.org/2/tutorial/floatingpoint.html





On Thu, 10 Jan 2013 20:15:45 +0800, Nick Cox <njcoxstata@gmail.com> wrote:

I don't think that is a clear specification of what Stata is doing (it
doesn't "make up its own digits") or of what it should, in your view,
do instead.

If you want _display_ to a fixed number of decimal places, that is
ultimately a question of formatting and not a problem of numerics.
That is,

display %3.2 f  1 + 98/100

will ensure that you see "1.98" and this last step is in essence
string manipulation with numeric characters. But all that is done by
(e.g.)

scalar foo = 1.98

is putting a binary approximation of 1.98 in a scalar. Adding bits
will change the accuracy of the approximation (only).
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


--
Patrick Toche.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index