Post Reply 
[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
[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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
[Help: CAS Code] Comparing exact with approx expressions - compsystems - 11-05-2016 02:57 PM



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