view test/recursion.tst @ 20154:45565ecec019

New function psi to compute the digamma function. * libinterp/corefcn/psi.cc: file for the new function file (implementation is actually in lo-specfun.cc). * liboctave/numeric/lo-specfun.cc, liboctave/numeric/lo-specfun.h: added implementation of the digamma (psi )function. Partly based on diGamma() from XLiFE++ 1.1 (file gammaFunctions.cpp which was previously melina++) which is under GPL 3 or later and why D. Martin is also added to copyright. * doc/interpreter/arith.txi: add function entry to the manual. * libinterp/corefcn/module.mk: add file to the build system. * NEWS: note new function.
author Carnë Draug <carandraug@octave.org>
date Sun, 15 Mar 2015 03:31:16 +0000
parents 4197fc428c7d
children
line wrap: on
line source

## Copyright (C) 2006-2015 John W. Eaton
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

%!function y = f (x)
%!  if (x == 1)
%!    y = x;
%!    return;
%!  else
%!    y = x * f (x-1);
%!  endif
%!endfunction
%!
%!assert (f (5), 120)

%!function y = f (x)
%!  if (x == 1)
%!    y = x;
%!    return;
%!  else
%!    y = f (x-1) * x;
%!  endif
%!endfunction
%!
%!assert (f (5), 120)

%%FIXME: Need test for maximum recursion depth