Skip to content

Commit

Permalink
fix #988 anonymous function serialization '.^' and '^' were inversed. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed Oct 25, 2023
1 parent b6c6e1a commit 8a45706
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- adjust position `xlabel` on `figure`.
- [#976](http://github.com/Nelson-numerical-software/nelson/issues/976) wrong output when reading a file with fscanf with size argument.
- [#975](http://github.com/Nelson-numerical-software/nelson/issues/975) Legend color (and width) is not matching that of curve in figure.
- [#988](http://github.com/Nelson-numerical-software/nelson/issues/988) anonymous function serialization '.^' and '^' are inversed.

## 0.7.9 (2023-09-18)

Expand Down
20 changes: 20 additions & 0 deletions modules/function_handle/tests/bug_github_issue_#988.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
%=============================================================================
% Copyright (c) 2017 Allan CORNET (Nelson)
%=============================================================================
% This file is part of the Nelson.
%=============================================================================
% LICENCE_BLOCK_BEGIN
% SPDX-License-Identifier: LGPL-3.0-or-later
% LICENCE_BLOCK_END
%=============================================================================
% <-- Issue URL -->
% https://github.com/Nelson-numerical-software/nelson/issues/988
% <-- Short Description -->
% anonymous function serialization '.^' and '^' were inversed.
%=============================================================================
F1 = @(f) f .^2
assert_isequal(func2str(F1), '@(f)f.^2')
%=============================================================================
F2 = @(f) f ^2
assert_isequal(func2str(F2), '@(f)f^2')
%=============================================================================
4 changes: 2 additions & 2 deletions modules/function_handle/tests/test_function_anonymous.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
REF = 31.50;
assert_isequal(R, REF);
%=============================================================================
F = @(c) (integral(@(x) (x.^2 + c*x + 1),0,1));
F = @(c) (integral(@(x) (x .^ 2 + c*x + 1),0,1));
R = func2str(F);
REF = '@(c)integral(@(x)x^2+c*x+1,0,1)';
REF = '@(c)integral(@(x)x.^2+c*x+1,0,1)';
assert_isequal(R, REF);
%=============================================================================
myfunction = @(x,y) (x^2 + y^2 + x*y);
Expand Down
4 changes: 2 additions & 2 deletions modules/interpreter/src/cpp/AbstractSyntaxTreeHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ expression(AbstractSyntaxTreePtr expr)
res = expression(expr->down) + ".\\" + expression(expr->down->right);
} break;
case OP_POWER: {
res = expression(expr->down) + "^" + expression(expr->down->right);
res = expression(expr->down) + ".^" + expression(expr->down->right);
} break;
case OP_MPOWER: {
res = expression(expr->down) + ".^" + expression(expr->down->right);
res = expression(expr->down) + "^" + expression(expr->down->right);
} break;
case OP_FUNCTION_HANDLE_ANONYMOUS: {
res = "@(";
Expand Down

0 comments on commit 8a45706

Please sign in to comment.