Google Группы больше не поддерживают новые публикации и подписки в сети Usenet. Опубликованный ранее контент останется доступен.
Закрыть

Re: Clip[] doesn't work as expected

8 просмотров
Перейти к первому непрочитанному сообщению

Bob Hanlon

не прочитано,
8 янв. 2011 г., 03:37:2508.01.2011

$Version

"8.0 for Mac OS X x86 (64-bit) (November 6, 2010)"

Clip[1.00000000000000036, {0., 1.}]

1.

Verifying that extra digits are not just suppressed for output display

% // InputForm

1.


Bob Hanlon

---- Yen Lee Loh <yenle...@gmail.com> wrote:

=============
On Mathematica v7.0.1 on Mac OS X,


Clip[1.00000000000000036, {0., 1.}]


gives


1.0000000000000004


upon close examination of the output. The documentation does not warn of
this behavior.
I have not checked if the same thing happens in Mathematica v8.
Just thought I would let you know.

Yen Lee


Leonid Shifrin

не прочитано,
9 янв. 2011 г., 02:19:4909.01.2011
This behavior is correct, and there is nothing to warn about. You use
machine-precision arithmetic,
and your result is within machine epsilon of 1:

In[1]:=Chop[Clip[1.00000000000000036,{0,1}]-1]

Out[1] = 0

If you want exact result, you need fixed higher precision, and exact bounds
in Clip, such as:

In[2]:= Clip[N[1+36*10^(-17),20],{0,1}]

Out[2]= 1


Regards,
Leonid

Alexey Popkov

не прочитано,
10 янв. 2011 г., 02:33:4910.01.2011
"Leonid Shifrin" <lsh...@gmail.com> news:igbnil$hi0$1...@smc.vnet.net...

> This behavior is correct, and there is nothing to warn about. You use
> machine-precision arithmetic,
> and your result is within machine epsilon of 1:
>
> In[1]:=Chop[Clip[1.00000000000000036,{0,1}]-1]
>
> Out[1] = 0
>
> If you want exact result, you need fixed higher precision, and exact
bounds
> in Clip, such as:
>
> In[2]:= Clip[N[1+36*10^(-17),20],{0,1}]
>
> Out[2]= 1
>
>
> Regards,
> Leonid


I think that there is no excuse for this:
In[6]:= Clip[1.00000000000000003`18, {0, 1}]
Out[6]= 1.00000000000000003

Leonid Shifrin

не прочитано,
11 янв. 2011 г., 00:32:3011.01.2011
I agree with this. This part of Clip's behavior looks like a bug indeed.
Seems to have been fixed in Mathematica 8.
0 новых сообщений