Mercurial > octave
changeset 24515:070e9b036141
primes.m: Correctly return output of same class as input (bug #52787).
* primes.m: Assign output variable 'p' to be the result of casting
'p' to the desired class. Use '@:' Texinfo to create a non-sentence
ending period for etc. Add BIST tests for output class.
author | Sahil Yadav <yadavsahil5198@gmail.com> |
---|---|
date | Wed, 03 Jan 2018 11:16:47 +0530 |
parents | 2bee24503a13 |
children | b31fa0a0bca2 |
files | scripts/specfun/primes.m |
diffstat | 1 files changed, 6 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/specfun/primes.m Thu Jan 04 10:07:31 2018 -0800 +++ b/scripts/specfun/primes.m Wed Jan 03 11:16:47 2018 +0530 @@ -17,13 +17,13 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {} {} primes (@var{n}) +## @deftypefn {} {@var{p} =} primes (@var{n}) ## Return all primes up to @var{n}. ## -## The output data class (double, single, uint32, etc.) is the same as the +## The output data class (double, single, uint32, etc.@:) is the same as the ## input class of @var{n}. The algorithm used is the Sieve of Eratosthenes. ## -## Notes: If you need a specific number of primes you can use the fact that the +## Note: If you need a specific number of primes you can use the fact that the ## distance from one prime to the next is, on average, proportional to the ## logarithm of the prime. Integrating, one finds that there are about ## @math{k} primes less than @@ -94,7 +94,7 @@ endif if (! isa (n, "double")) - cast (p, class (n)); + p = cast (p, class (n)); endif endfunction @@ -102,6 +102,8 @@ %!assert (size (primes (350)), [1, 70]) %!assert (primes (357)(end), 353) +%!assert (class (primes (single (10))), "single") +%!assert (class (primes (uint8 (10))), "uint8") %!error primes () %!error primes (1, 2)