Expecting errors,warnings

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Expecting errors,warnings

Dildar Sk
When I type,
>> list_primes (-10)
ans = [](0x0)
>> primes(-20)
ans = [](1x0)
>>

Isn't it valid to produce error, warning instead of giving a empty vector in
case of negative numbers input?



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html

Reply | Threaded
Open this post in threaded view
|

Re: Expecting errors,warnings

Michele Ginesi
On 03/23/2018 08:48 AM, Dildar Sk wrote:

> When I type,
>>> list_primes (-10)
> ans = [](0x0)
>>> primes(-20)
> ans = [](1x0)
> Isn't it valid to produce error, warning instead of giving a empty vector in
> case of negative numbers input?
>
>
>
> --
> Sent from: http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html
>

I think is done for Matlab compatibility: Matlab2017b doesn't have the
function list_primes, however

 >> primes(-20)

ans =

   1×0 empty double row vector

So I suppose that list_primes does not give error for coherence with
primes (even if maybe it should still be a 1x0 vector instead of a 0x0)

--
Michele Ginesi


Reply | Threaded
Open this post in threaded view
|

Re: Expecting errors,warnings

Dildar Sk
Then,Why
Octave produces,
>> isprime(5i)
ans = 0
>> isprime(-20)
ans = 0
>> isprime(3+4i)
ans = 0
>>

When MATLAB produces errors in such input.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html