Mercurial > octave-dspies
comparison libinterp/octave-value/ov-fcn-inline.cc @ 15977:6535f92350ec
Always give inline functions a default argument (bug #38164)
* ov-fc-inline.cc (Finline): Append "x" as an input argument if none
exists. Document this behaviour. Add tests.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 24 Jan 2013 17:05:30 -0500 |
parents | 2fc554ffbc28 |
children | dc5d42399e89 |
comparison
equal
deleted
inserted
replaced
15976:bbce6de5c0a5 | 15977:6535f92350ec |
---|---|
643 function are extracted from the function itself. The generated\n\ | 643 function are extracted from the function itself. The generated\n\ |
644 function arguments will then be in alphabetical order. It should\n\ | 644 function arguments will then be in alphabetical order. It should\n\ |
645 be noted that i, and j are ignored as arguments due to the\n\ | 645 be noted that i, and j are ignored as arguments due to the\n\ |
646 ambiguity between their use as a variable or their use as an inbuilt\n\ | 646 ambiguity between their use as a variable or their use as an inbuilt\n\ |
647 constant. All arguments followed by a parenthesis are considered\n\ | 647 constant. All arguments followed by a parenthesis are considered\n\ |
648 to be functions.\n\ | 648 to be functions. If no arguments are found, a function taking a single\n\ |
649 argument named @code{x} will be created.\n\ | |
649 \n\ | 650 \n\ |
650 If the second and subsequent arguments are character strings,\n\ | 651 If the second and subsequent arguments are character strings,\n\ |
651 they are the names of the arguments of the function.\n\ | 652 they are the names of the arguments of the function.\n\ |
652 \n\ | 653 \n\ |
653 If the second argument is an integer @var{n}, the arguments are\n\ | 654 If the second argument is an integer @var{n}, the arguments are\n\ |
750 } | 751 } |
751 } | 752 } |
752 | 753 |
753 // Sort the arguments into ascii order. | 754 // Sort the arguments into ascii order. |
754 fargs.sort (); | 755 fargs.sort (); |
756 | |
757 if (fargs.length () == 0) | |
758 fargs.append (std::string ("x")); | |
759 | |
755 } | 760 } |
756 else if (nargin == 2 && args(1).is_numeric_type ()) | 761 else if (nargin == 2 && args(1).is_numeric_type ()) |
757 { | 762 { |
758 if (! args(1).is_scalar_type ()) | 763 if (! args(1).is_scalar_type ()) |
759 { | 764 { |
823 /* | 828 /* |
824 %!shared fn | 829 %!shared fn |
825 %! fn = inline ("x.^2 + 1"); | 830 %! fn = inline ("x.^2 + 1"); |
826 %!assert (feval (fn, 6), 37) | 831 %!assert (feval (fn, 6), 37) |
827 %!assert (fn (6), 37) | 832 %!assert (fn (6), 37) |
828 ## FIXME: Need tests for other 2 calling forms of inline() | 833 %!assert (feval (inline ("sum (x(:))"), [1 2; 3 4]), 10) |
834 %!assert (feval (inline ("sqrt (x^2 + y^2)", "x", "y"), 3, 4), 5) | |
835 %!assert (feval (inline ("exp (P1*x) + P2", 3), 3, 4, 5), exp(3*4) + 5) | |
829 | 836 |
830 ## Test input validation | 837 ## Test input validation |
831 %!error inline () | 838 %!error inline () |
832 %!error <STR argument must be a string> inline (1) | 839 %!error <STR argument must be a string> inline (1) |
833 %!error <N must be an integer> inline ("2", ones (2,2)) | 840 %!error <N must be an integer> inline ("2", ones (2,2)) |