[Help: CAS Code] Comparing exact with approx expressions
11-05-2016, 02:57 PM (This post was last modified: 01-04-2017 04:32 AM by compsystems.)
Post: #1
 compsystems Senior Member Posts: 1,342 Joined: Dec 2013
[Help: CAS Code] Comparing exact with approx expressions
I want to print in the terminal window, a numeric or symbolic value, depending on whether, is the same or different in their approximate or exact value, to avoid print two the same result. For this I am writing a program that compares two expressions exactSameApprox(expr1, expr2)

PHP Code:
#cas

exactSameApprox(expr1expr2):=

begin

//print(delDot(expr1) == delDot(expr2)); wait();

if eq(delDot(expr1),delDot(expr2)) == true then

return true;
else
return
false;

end;

end;

delDotmExpr ):=

begin
local exprStr
:= stringmExpr );
if
fpapproxmExpr ) ) == 0 then
exprStr
:= left(exprStrinstring(exprStr,".")-1); // the decimal dot is deleted when the fractional part is zero

end;
return
exprStr;

end;
#end

terms

1: If the approximate value is the same that exact return "TRUE"

exactSameApprox(5, 5) -> true
"5" same "5" -> true

numbers with fractional part == 0, are considered equals, it requires a function to remove the fractional part delDot( mExpr )
exactSameApprox(1, 1.0) -> true or
exactSameApprox(1, 1.) -> true or
exactSameApprox(1.0, 1) -> true or
1.0 -> 1
"1" same "1" -> true

2: if the exact value is different from the approximate value must be return FALSE, BUT MY CODE FAILS.

exactSameApprox(2, 4/2) -> true // FAIL =( must be return FALSE
"2" same "4/2" -> false

Who can help me improve the code above?
the problem is that when storing, or convert to string a mathematical expression, this first is evaluated.
Using QUOTE (not to recall the argument of the input arg) to convert string =(

PHP Code:
deldot(mexpr):=
begin
local exprstr
:= stringquote(mexpr) ); // -> exprstr:=" 'mexpr' " and not 'rcl(mexpr)',

Thanks
 « Next Oldest | Next Newest »

 Messages In This Thread [Help: CAS Code] Comparing exact with approx expressions - compsystems - 11-05-2016 02:57 PM RE: [Help: CAS Code] Comparing exact with approx expressions - compsystems - 11-05-2016, 08:39 PM RE: [Help: CAS Code] Comparing exact with approx expressions - CH3791 - 11-05-2016, 11:27 PM

User(s) browsing this thread: 1 Guest(s)