Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Clip[] doesn't work as expected

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115376] Re: Clip[] doesn't work as expected
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Sun, 9 Jan 2011 02:19:54 -0500 (EST)

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


On Fri, Jan 7, 2011 at 12:11 PM, Yen Lee Loh <yenleeloh1 at 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
>
>
>


  • Prev by Date: Re: Combining Slider and SetterBar in Manipulate
  • Next by Date: Re: Clip[] doesn't work as expected
  • Previous by thread: Re: Clip[] doesn't work as expected
  • Next by thread: Re: Clip[] doesn't work as expected