Help with linspace

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with linspace

Rik-4
Could someone with access to Matlab try the following?

linspace(-0, 0, 5)

Octave returns

ans =

  -0   0   0   0   0

which is pretty silly unless it is required for compatibility.

--Rik

Reply | Threaded
Open this post in threaded view
|

Re: Help with linspace

bpabbott
Administrator
> On Jan 6, 2018, at 7:23 AM, Rik <[hidden email]> wrote:
>
> Could someone with access to Matlab try the following?
>
> linspace(-0, 0, 5)
>
> Octave returns
>
> ans =
>
>   -0   0   0   0   0
>
> which is pretty silly unless it is required for compatibility.
>
> —Rik

Using R2016a ...

linspace(-0, 0, 5)

ans =

     0     0     0     0     0

Ben
Reply | Threaded
Open this post in threaded view
|

Re: Help with linspace

Urathai
Ben Abbott writes:

>> On Jan 6, 2018, at 7:23 AM, Rik <[hidden email]> wrote:
>>
>> Could someone with access to Matlab try the following?
>>
>> linspace(-0, 0, 5)
>>
>> Octave returns
>>
>> ans =
>>
>>   -0   0   0   0   0
>>
>> which is pretty silly unless it is required for compatibility.
>>
>> —Rik
>
> Using R2016a ...
>
> linspace(-0, 0, 5)
>
> ans =
>
>      0     0     0     0     0
>
> Ben

Matlab does not show the sign of 0. In fact it does indeed return [-0,
0, 0, 0, 0]. An easy way to check is

1./(linspace(-0, 0, 5))

ans =

  -Inf   Inf   Inf   Inf   Inf

Joel
Reply | Threaded
Open this post in threaded view
|

Re: Help with linspace

Rik-4
In reply to this post by bpabbott
On 01/06/2018 07:56 AM, Ben Abbott wrote:

>> On Jan 6, 2018, at 7:23 AM, Rik <[hidden email]> wrote:
>>
>> Could someone with access to Matlab try the following?
>>
>> linspace(-0, 0, 5)
>>
>> Octave returns
>>
>> ans =
>>
>>   -0   0   0   0   0
>>
>> which is pretty silly unless it is required for compatibility.
>>
>> —Rik
> Using R2016a ...
>
> linspace(-0, 0, 5)
>
> ans =
>
>      0     0     0     0     0
>
> Ben
>
>
>

Okay, silly, but overruled.

--Rik


Reply | Threaded
Open this post in threaded view
|

Re: Help with linspace

Michael Godfrey


On 01/06/2018 05:44 PM, Rik wrote:
On 01/06/2018 07:56 AM, Ben Abbott wrote:
On Jan 6, 2018, at 7:23 AM, Rik [hidden email] wrote:

Could someone with access to Matlab try the following?

linspace(-0, 0, 5)

Octave returns

ans =

  -0   0   0   0   0

which is pretty silly unless it is required for compatibility.

—Rik
Using R2016a ...

linspace(-0, 0, 5)

ans =

     0     0     0     0     0

Ben



Okay, silly, but overruled.

--Rik


Right! Pretty cute of Matlab to hide the -
Reply | Threaded
Open this post in threaded view
|

Re: Help with linspace

Daniel Sebald
In reply to this post by Urathai
On 01/06/2018 11:04 AM, Joel Dahne wrote:
> Ben Abbott writes:
>
[snip]

>> Using R2016a ...
>>
>> linspace(-0, 0, 5)
>>
>> ans =
>>
>>       0     0     0     0     0
>>
>> Ben
>
> Matlab does not show the sign of 0. In fact it does indeed return [-0,
> 0, 0, 0, 0]. An easy way to check is
>
> 1./(linspace(-0, 0, 5))
>
> ans =
>
>    -Inf   Inf   Inf   Inf   Inf

Nice manner of testing...  Consider adding this to the list of linspace
compatibility tests in data.cc:

Dan

Reply | Threaded
Open this post in threaded view
|

Re: Help with linspace

Michele Ginesi
On 01/06/2018 07:20 PM, Daniel J Sebald wrote:

> On 01/06/2018 11:04 AM, Joel Dahne wrote:
>> Ben Abbott writes:
>>
> [snip]
>>> Using R2016a ...
>>>
>>> linspace(-0, 0, 5)
>>>
>>> ans =
>>>
>>>       0     0     0     0     0
>>>
>>> Ben
>>
>> Matlab does not show the sign of 0. In fact it does indeed return [-0,
>> 0, 0, 0, 0]. An easy way to check is
>>
>> 1./(linspace(-0, 0, 5))
>>
>> ans =
>>
>>    -Inf   Inf   Inf   Inf   Inf
>
> Nice manner of testing...  Consider adding this to the list of
> linspace compatibility tests in data.cc:
>
> Dan
>

Actually, on Matlab R2017b

 >> linspace(-0, 0, 5)

ans =

      0     0     0     0     0

 >> 1./linspace(-0, 0, 5)

ans =

   -Inf  -Inf  -Inf  -Inf  -Inf

and

 >> linspace(0, -0, 5)

ans =

      0     0     0     0     0

 >> 1./linspace(0, -0, 5)

ans =

    Inf   Inf   Inf   Inf   Inf

--
Michele Ginesi


Reply | Threaded
Open this post in threaded view
|

Re: Help with linspace

John W. Eaton
Administrator
On 01/06/2018 02:00 PM, michele wrote:

>  >> 1./linspace(-0, 0, 5)
>
> ans =
>
>    -Inf  -Inf  -Inf  -Inf  -Inf

I guess it's an optimization of sorts.  It also seems pretty funny
because I think the final value is normally set to be the one given as
the end point.  Though I guess not in this case now.

jwe

Reply | Threaded
Open this post in threaded view
|

Re: Help with linspace

Rik-4
In reply to this post by Daniel Sebald
On 01/06/2018 10:20 AM, Daniel J Sebald wrote:

> On 01/06/2018 11:04 AM, Joel Dahne wrote:
>> Ben Abbott writes:
>>
> [snip]
>>> Using R2016a ...
>>>
>>> linspace(-0, 0, 5)
>>>
>>> ans =
>>>
>>>       0     0     0     0     0
>>>
>>> Ben
>>
>> Matlab does not show the sign of 0. In fact it does indeed return [-0,
>> 0, 0, 0, 0]. An easy way to check is
>>
>> 1./(linspace(-0, 0, 5))
>>
>> ans =
>>
>>    -Inf   Inf   Inf   Inf   Inf
>
> Nice manner of testing...  Consider adding this to the list of linspace
> compatibility tests in data.cc:

Done.  See http://hg.savannah.gnu.org/hgweb/octave/rev/22a2bc91cc7f.

--Rik

Reply | Threaded
Open this post in threaded view
|

Re: Help with linspace

nrjank
In reply to this post by bpabbott


On Jan 6, 2018 10:57 AM, "Ben Abbott" <[hidden email]> wrote:
> On Jan 6, 2018, at 7:23 AM, Rik <[hidden email]> wrote:
>
> Could someone with access to Matlab try the following?
>
> linspace(-0, 0, 5)
>
> Octave returns
>
> ans =
>
>   -0   0   0   0   0
>
> which is pretty silly unless it is required for compatibility.
>
> —Rik

Using R2016a ...

linspace(-0, 0, 5)

ans =

     0     0     0     0     0

Ben

So... Ignoring what MATLAB show, has, or hides for the moment, was is (if anything) Octave's intent on following IEEE 754 that requires both pos and neg zero?